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)
| 21 | // waitForNamespaceCount polls ListNamespaces until the expected count is reached or timeout. |
| 22 | // This is needed because DropAll and DropNamespace are asynchronous operations. |
| 23 | func 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 | |
| 47 | func TestNamespaces(t *testing.T) { |
| 48 | dc := dgraphtest.NewComposeCluster() |
no test coverage detected