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

Function waitForNamespaceCount

edgraph/namespace_test.go:23–45  ·  view source on GitHub ↗

waitForNamespaceCount polls ListNamespaces until the expected count is reached or timeout. This is needed because DropAll and DropNamespace are asynchronous operations.

(t *testing.T, client *dgraphapi.GrpcClient, expected int, timeout time.Duration)

Source from the content-addressed store, hash-verified

21// waitForNamespaceCount polls ListNamespaces until the expected count is reached or timeout.
22// This is needed because DropAll and DropNamespace are asynchronous operations.
23func waitForNamespaceCount(t *testing.T, client *dgraphapi.GrpcClient, expected int, timeout time.Duration) {
24 t.Helper()
25 ctx := context.Background()
26 deadline := time.Now().Add(timeout)
27
28 for time.Now().Before(deadline) {
29 nsMaps, err := client.ListNamespaces(ctx)
30 if err != nil {
31 t.Logf("ListNamespaces error (will retry): %v", err)
32 time.Sleep(100 * time.Millisecond)
33 continue
34 }
35 if len(nsMaps) == expected {
36 return
37 }
38 time.Sleep(100 * time.Millisecond)
39 }
40
41 // Final check with assertion on timeout
42 nsMaps, err := client.ListNamespaces(ctx)
43 require.NoError(t, err)
44 require.Len(t, nsMaps, expected)
45}
46
47func TestNamespaces(t *testing.T) {
48 dc := dgraphtest.NewComposeCluster()

Callers 1

TestDropNamespaceErrFunction · 0.85

Calls 3

LenMethod · 0.65
AddMethod · 0.45
ListNamespacesMethod · 0.45

Tested by

no test coverage detected