MCPcopy
hub / github.com/dgraph-io/dgraph / TestZeroGracefulShutdown

Function TestZeroGracefulShutdown

dgraph/cmd/zero/zero_test.go:159–192  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

157}
158
159func TestZeroGracefulShutdown(t *testing.T) {
160 // This test verifies that Zero shuts down cleanly without hanging.
161 // It catches issues like closer miscount bugs where SignalAndWait() would block indefinitely.
162
163 instance := testutil.GetContainerInstance(testutil.DockerPrefix, "zero1")
164 c := instance.GetContainer()
165 require.NotNil(t, c, "zero1 container not found")
166
167 containerID := c.ID
168
169 startTime := time.Now()
170 err := testutil.DockerRun("zero1", testutil.Stop)
171 shutdownDuration := time.Since(startTime)
172
173 require.NoError(t, err, "Failed to stop zero1 container")
174 cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
175 require.NoError(t, err)
176
177 inspect, err := cli.ContainerInspect(context.Background(), containerID)
178 require.NoError(t, err)
179 require.False(t, inspect.State.Running, "Container should not be running after stop")
180
181 if inspect.State.ExitCode == 137 {
182 t.Errorf("Zero was killed (exit code 137) instead of shutting down gracefully. "+
183 "This may indicate a hanging goroutine or closer miscount. Shutdown took %v", shutdownDuration)
184 }
185
186 // Restart the container so other tests can continue
187 err = testutil.DockerRun("zero1", testutil.Start)
188 require.NoError(t, err, "Failed to restart zero1 container")
189
190 err = instance.BestEffortWaitForHealthy(6080)
191 require.NoError(t, err, "Zero did not become healthy after restart")
192}

Callers

nothing calls this directly

Calls 5

GetContainerInstanceFunction · 0.92
DockerRunFunction · 0.92
GetContainerMethod · 0.80
ErrorfMethod · 0.45

Tested by

no test coverage detected