MCPcopy
hub / github.com/moby/moby / TestEventsVolumeCreate

Function TestEventsVolumeCreate

integration/system/event_test.go:76–141  ·  view source on GitHub ↗

TestEventsVolumeCreate verifies that volume create events are only fired once: when creating the volume, and not when attaching to a container.

(t *testing.T)

Source from the content-addressed store, hash-verified

74// TestEventsVolumeCreate verifies that volume create events are only fired
75// once: when creating the volume, and not when attaching to a container.
76func TestEventsVolumeCreate(t *testing.T) {
77 skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME: Windows doesn't trigger the events? Could be a race")
78
79 ctx := setupTest(t)
80 ctx, cancel := context.WithCancel(ctx)
81 defer cancel()
82
83 apiClient := testEnv.APIClient()
84
85 since := request.DaemonUnixTime(ctx, t, apiClient, testEnv)
86 volName := t.Name()
87 getEvents := func(messages <-chan events.Message, errs <-chan error) ([]events.Message, error) {
88 var evts []events.Message
89
90 for {
91 select {
92 case m := <-messages:
93 evts = append(evts, m)
94 case err := <-errs:
95 if errors.Is(err, io.EOF) {
96 return evts, nil
97 }
98 return nil, err
99 case <-time.After(time.Second * 3):
100 return nil, errors.New("timeout hit")
101 }
102 }
103 }
104
105 _, err := apiClient.VolumeCreate(ctx, client.VolumeCreateOptions{Name: volName})
106 assert.NilError(t, err)
107
108 filter := make(client.Filters).
109 Add("type", "volume").
110 Add("event", "create").
111 Add("volume", volName)
112 result := apiClient.Events(ctx, client.EventsListOptions{
113 Since: since,
114 Until: request.DaemonUnixTime(ctx, t, apiClient, testEnv),
115 Filters: filter,
116 })
117 messages := result.Messages
118 errs := result.Err
119
120 volEvents, err := getEvents(messages, errs)
121 assert.NilError(t, err)
122 assert.Equal(t, len(volEvents), 1, "expected volume create event when creating a volume")
123
124 container.Create(ctx, t, apiClient, container.WithMount(mount.Mount{
125 Type: mount.TypeVolume,
126 Source: volName,
127 Target: "/tmp/foo",
128 }))
129
130 result = apiClient.Events(ctx, client.EventsListOptions{
131 Since: since,
132 Until: request.DaemonUnixTime(ctx, t, apiClient, testEnv),
133 Filters: filter,

Callers

nothing calls this directly

Calls 12

DaemonUnixTimeFunction · 0.92
CreateFunction · 0.92
WithMountFunction · 0.92
APIClientMethod · 0.80
EqualMethod · 0.80
setupTestFunction · 0.70
NameMethod · 0.65
NewMethod · 0.65
VolumeCreateMethod · 0.65
AddMethod · 0.65
EventsMethod · 0.65
IsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…