nolint:maintidx // Come on, it is a test.
(t *testing.T)
| 30 | |
| 31 | //nolint:maintidx // Come on, it is a test. |
| 32 | func TestManager(t *testing.T) { |
| 33 | ctx, cancel := context.WithCancel(context.Background()) |
| 34 | defer cancel() |
| 35 | |
| 36 | log.SetLevel(log.TraceLevel) |
| 37 | |
| 38 | opts := testutils.DefaultAgentConfig(3) |
| 39 | mopts := testutils.ElasticMasterSetAgentConfig() |
| 40 | |
| 41 | t.Log("building client") |
| 42 | rawCl, err := dclient.NewClientWithOpts(dclient.WithAPIVersionNegotiation(), dclient.FromEnv) |
| 43 | require.NoError(t, err) |
| 44 | defer func() { |
| 45 | if cErr := rawCl.Close(); cErr != nil { |
| 46 | t.Logf("closing docker client: %s", cErr) |
| 47 | } |
| 48 | }() |
| 49 | cl := docker.NewClient(rawCl) |
| 50 | |
| 51 | t.Log("setting up event handler") |
| 52 | evs := make(chan container.Event, 5024) |
| 53 | f := events.ChannelPublisher(evs) |
| 54 | |
| 55 | t.Log("creating container manager") |
| 56 | m, err := containers.New(opts, mopts, nil, cl, f) |
| 57 | require.NoError(t, err) |
| 58 | defer m.Close() |
| 59 | |
| 60 | t.Log("running a few successful test containers") |
| 61 | expectedSuccesses := map[cproto.ID]bool{} |
| 62 | countSuccesses := 12 |
| 63 | for i := 0; i < countSuccesses; i++ { |
| 64 | cID := cproto.ID(uuid.NewString()) |
| 65 | err = m.StartContainer(ctx, aproto.StartContainer{ |
| 66 | Container: cproto.Container{ |
| 67 | ID: cID, |
| 68 | State: cproto.Assigned, |
| 69 | Devices: []device.Device{}, |
| 70 | }, |
| 71 | Spec: cproto.Spec{ |
| 72 | TaskType: string(model.TaskTypeCommand), |
| 73 | RunSpec: cproto.RunSpec{ |
| 74 | ContainerConfig: dcontainer.Config{ |
| 75 | Image: "python", |
| 76 | Entrypoint: []string{"echo", "hello"}, |
| 77 | }, |
| 78 | }, |
| 79 | }, |
| 80 | }) |
| 81 | require.NoError(t, err) |
| 82 | expectedSuccesses[cID] = true |
| 83 | } |
| 84 | |
| 85 | t.Log("running a few unsuccessful test containers") |
| 86 | countFailures := 12 |
| 87 | expectedFailures := map[cproto.ID]bool{} |
| 88 | for i := 0; i < countFailures; i++ { |
| 89 | cID := cproto.ID(uuid.NewString()) |
nothing calls this directly
no test coverage detected