Skip to content

Commit 830b3c2

Browse files
committed
integration: Enable some tests for Windows (part 2)
Some of the tests that are currently running only on Linux can be made to run on Windows with a few changes. Signed-off-by: Claudiu Belu <[email protected]>
1 parent d97b40c commit 830b3c2

8 files changed

Lines changed: 440 additions & 402 deletions

integration/client/container_linux_test.go

Lines changed: 0 additions & 309 deletions
Original file line numberDiff line numberDiff line change
@@ -238,76 +238,6 @@ func TestShimInCgroup(t *testing.T) {
238238
<-statusC
239239
}
240240

241-
func TestDaemonRestart(t *testing.T) {
242-
client, err := newClient(t, address)
243-
if err != nil {
244-
t.Fatal(err)
245-
}
246-
defer client.Close()
247-
248-
var (
249-
image Image
250-
ctx, cancel = testContext(t)
251-
id = t.Name()
252-
)
253-
defer cancel()
254-
255-
image, err = client.GetImage(ctx, testImage)
256-
if err != nil {
257-
t.Fatal(err)
258-
}
259-
260-
container, err := client.NewContainer(ctx, id, WithNewSnapshot(id, image), WithNewSpec(oci.WithImageConfig(image), withProcessArgs("sleep", "30")))
261-
if err != nil {
262-
t.Fatal(err)
263-
}
264-
defer container.Delete(ctx, WithSnapshotCleanup)
265-
266-
task, err := container.NewTask(ctx, empty())
267-
if err != nil {
268-
t.Fatal(err)
269-
}
270-
defer task.Delete(ctx)
271-
272-
statusC, err := task.Wait(ctx)
273-
if err != nil {
274-
t.Fatal(err)
275-
}
276-
277-
if err := task.Start(ctx); err != nil {
278-
t.Fatal(err)
279-
}
280-
281-
var exitStatus ExitStatus
282-
if err := ctrd.Restart(func() {
283-
exitStatus = <-statusC
284-
}); err != nil {
285-
t.Fatal(err)
286-
}
287-
288-
if exitStatus.Error() == nil {
289-
t.Errorf(`first task.Wait() should have failed with "transport is closing"`)
290-
}
291-
292-
waitCtx, waitCancel := context.WithTimeout(ctx, 2*time.Second)
293-
serving, err := client.IsServing(waitCtx)
294-
waitCancel()
295-
if !serving {
296-
t.Fatalf("containerd did not start within 2s: %v", err)
297-
}
298-
299-
statusC, err = task.Wait(ctx)
300-
if err != nil {
301-
t.Fatal(err)
302-
}
303-
304-
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
305-
t.Fatal(err)
306-
}
307-
308-
<-statusC
309-
}
310-
311241
func TestShimDoesNotLeakPipes(t *testing.T) {
312242
containerdPid := ctrd.cmd.Process.Pid
313243
initialPipes, err := numPipes(containerdPid)
@@ -690,57 +620,6 @@ func TestContainerAttach(t *testing.T) {
690620
}
691621
}
692622

693-
func newDirectIO(ctx context.Context, terminal bool) (*directIO, error) {
694-
fifos, err := cio.NewFIFOSetInDir("", "", terminal)
695-
if err != nil {
696-
return nil, err
697-
}
698-
dio, err := cio.NewDirectIO(ctx, fifos)
699-
if err != nil {
700-
return nil, err
701-
}
702-
return &directIO{DirectIO: *dio}, nil
703-
}
704-
705-
type directIO struct {
706-
cio.DirectIO
707-
}
708-
709-
// ioCreate returns IO available for use with task creation
710-
func (f *directIO) IOCreate(id string) (cio.IO, error) {
711-
return f, nil
712-
}
713-
714-
// ioAttach returns IO available for use with task attachment
715-
func (f *directIO) IOAttach(set *cio.FIFOSet) (cio.IO, error) {
716-
return f, nil
717-
}
718-
719-
func (f *directIO) Cancel() {
720-
// nothing to cancel as all operations are handled externally
721-
}
722-
723-
// Close closes all open fds
724-
func (f *directIO) Close() error {
725-
err := f.Stdin.Close()
726-
if f.Stdout != nil {
727-
if err2 := f.Stdout.Close(); err == nil {
728-
err = err2
729-
}
730-
}
731-
if f.Stderr != nil {
732-
if err2 := f.Stderr.Close(); err == nil {
733-
err = err2
734-
}
735-
}
736-
return err
737-
}
738-
739-
// Delete removes the underlying directory containing fifos
740-
func (f *directIO) Delete() error {
741-
return f.DirectIO.Close()
742-
}
743-
744623
func TestContainerUsername(t *testing.T) {
745624
t.Parallel()
746625

@@ -1372,85 +1251,10 @@ func TestContainerRuntimeOptionsv2(t *testing.T) {
13721251
}
13731252
}
13741253

1375-
func initContainerAndCheckChildrenDieOnKill(t *testing.T, opts ...oci.SpecOpts) {
1376-
client, err := newClient(t, address)
1377-
if err != nil {
1378-
t.Fatal(err)
1379-
}
1380-
defer client.Close()
1381-
1382-
var (
1383-
image Image
1384-
ctx, cancel = testContext(t)
1385-
id = t.Name()
1386-
)
1387-
defer cancel()
1388-
1389-
image, err = client.GetImage(ctx, testImage)
1390-
if err != nil {
1391-
t.Fatal(err)
1392-
}
1393-
1394-
opts = append(opts, oci.WithImageConfig(image))
1395-
opts = append(opts, withProcessArgs("sh", "-c", "sleep 42; echo hi"))
1396-
1397-
container, err := client.NewContainer(ctx, id,
1398-
WithNewSnapshot(id, image),
1399-
WithNewSpec(opts...),
1400-
)
1401-
if err != nil {
1402-
t.Fatal(err)
1403-
}
1404-
defer container.Delete(ctx, WithSnapshotCleanup)
1405-
1406-
stdout := bytes.NewBuffer(nil)
1407-
task, err := container.NewTask(ctx, cio.NewCreator(withByteBuffers(stdout)))
1408-
if err != nil {
1409-
t.Fatal(err)
1410-
}
1411-
defer task.Delete(ctx)
1412-
1413-
statusC, err := task.Wait(ctx)
1414-
if err != nil {
1415-
t.Fatal(err)
1416-
}
1417-
1418-
if err := task.Start(ctx); err != nil {
1419-
t.Fatal(err)
1420-
}
1421-
1422-
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
1423-
t.Error(err)
1424-
}
1425-
1426-
// Give the shim time to reap the init process and kill the orphans
1427-
select {
1428-
case <-statusC:
1429-
case <-time.After(100 * time.Millisecond):
1430-
}
1431-
1432-
b, err := exec.Command("ps", "ax").CombinedOutput()
1433-
if err != nil {
1434-
t.Fatal(err)
1435-
}
1436-
1437-
if strings.Contains(string(b), "sleep 42") {
1438-
t.Fatalf("killing init didn't kill all its children:\n%v", string(b))
1439-
}
1440-
1441-
if _, err := task.Delete(ctx, WithProcessKill); err != nil {
1442-
t.Error(err)
1443-
}
1444-
}
1445-
14461254
func TestContainerKillInitPidHost(t *testing.T) {
14471255
initContainerAndCheckChildrenDieOnKill(t, oci.WithHostNamespace(specs.PIDNamespace))
14481256
}
14491257

1450-
func TestContainerKillInitKillsChildWhenNotHostPid(t *testing.T) {
1451-
initContainerAndCheckChildrenDieOnKill(t)
1452-
}
1453-
14541258
func TestUserNamespaces(t *testing.T) {
14551259
t.Parallel()
14561260
t.Run("WritableRootFS", func(t *testing.T) { testUserNamespaces(t, false) })
@@ -1570,49 +1374,6 @@ func testUserNamespaces(t *testing.T, readonlyRootFS bool) {
15701374
}
15711375
}
15721376

1573-
func TestTaskResize(t *testing.T) {
1574-
t.Parallel()
1575-
1576-
client, err := newClient(t, address)
1577-
if err != nil {
1578-
t.Fatal(err)
1579-
}
1580-
defer client.Close()
1581-
1582-
var (
1583-
image Image
1584-
ctx, cancel = testContext(t)
1585-
id = t.Name()
1586-
)
1587-
defer cancel()
1588-
1589-
image, err = client.GetImage(ctx, testImage)
1590-
if err != nil {
1591-
t.Fatal(err)
1592-
}
1593-
container, err := client.NewContainer(ctx, id, WithNewSnapshot(id, image), WithNewSpec(oci.WithImageConfig(image), withExitStatus(7)))
1594-
if err != nil {
1595-
t.Fatal(err)
1596-
}
1597-
defer container.Delete(ctx, WithSnapshotCleanup)
1598-
1599-
task, err := container.NewTask(ctx, empty())
1600-
if err != nil {
1601-
t.Fatal(err)
1602-
}
1603-
defer task.Delete(ctx)
1604-
1605-
statusC, err := task.Wait(ctx)
1606-
if err != nil {
1607-
t.Fatal(err)
1608-
}
1609-
if err := task.Resize(ctx, 32, 32); err != nil {
1610-
t.Fatal(err)
1611-
}
1612-
task.Kill(ctx, syscall.SIGKILL)
1613-
<-statusC
1614-
}
1615-
16161377
func TestUIDNoGID(t *testing.T) {
16171378
t.Parallel()
16181379

@@ -1868,73 +1629,3 @@ func TestShimOOMScore(t *testing.T) {
18681629

18691630
<-statusC
18701631
}
1871-
1872-
func TestTaskSpec(t *testing.T) {
1873-
t.Parallel()
1874-
1875-
client, err := newClient(t, address)
1876-
if err != nil {
1877-
t.Fatal(err)
1878-
}
1879-
defer client.Close()
1880-
1881-
var (
1882-
image Image
1883-
ctx, cancel = testContext(t)
1884-
id = t.Name()
1885-
)
1886-
defer cancel()
1887-
1888-
image, err = client.GetImage(ctx, testImage)
1889-
if err != nil {
1890-
t.Fatal(err)
1891-
}
1892-
1893-
container, err := client.NewContainer(ctx, id, WithNewSnapshot(id, image), WithNewSpec(oci.WithImageConfig(image), longCommand))
1894-
if err != nil {
1895-
t.Fatal(err)
1896-
}
1897-
defer container.Delete(ctx, WithSnapshotCleanup)
1898-
1899-
task, err := container.NewTask(ctx, empty())
1900-
if err != nil {
1901-
t.Fatal(err)
1902-
}
1903-
defer task.Delete(ctx)
1904-
1905-
statusC, err := task.Wait(ctx)
1906-
if err != nil {
1907-
t.Fatal(err)
1908-
}
1909-
1910-
spec, err := task.Spec(ctx)
1911-
if err != nil {
1912-
t.Fatal(err)
1913-
}
1914-
if spec == nil {
1915-
t.Fatal("spec from task is nil")
1916-
}
1917-
direct, err := newDirectIO(ctx, false)
1918-
if err != nil {
1919-
t.Fatal(err)
1920-
}
1921-
defer direct.Delete()
1922-
1923-
lt, err := container.Task(ctx, direct.IOAttach)
1924-
if err != nil {
1925-
t.Fatal(err)
1926-
}
1927-
1928-
spec, err = lt.Spec(ctx)
1929-
if err != nil {
1930-
t.Fatal(err)
1931-
}
1932-
if spec == nil {
1933-
t.Fatal("spec from loaded task is nil")
1934-
}
1935-
1936-
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
1937-
t.Fatal(err)
1938-
}
1939-
<-statusC
1940-
}

0 commit comments

Comments
 (0)