diff --git a/internal/driver/config/namespace_watcher_test.go b/internal/driver/config/namespace_watcher_test.go index 288fe3006..9819647e4 100644 --- a/internal/driver/config/namespace_watcher_test.go +++ b/internal/driver/config/namespace_watcher_test.go @@ -8,7 +8,6 @@ import ( "path/filepath" "strings" "testing" - "time" "github.com/ghodss/yaml" "github.com/ory/x/logrusx" @@ -21,22 +20,6 @@ import ( "github.com/ory/keto/internal/namespace" ) -func runWithTimeOut(t *testing.T, duration time.Duration, testfn func(*testing.T)) { - timeout := time.After(duration) - done := make(chan bool) - - go func() { - testfn(t) - done <- true - }() - - select { - case <-timeout: - t.Fatalf("test did not complete after %s\n", duration) - case <-done: - } -} - func TestNamespaceProvider(t *testing.T) { setup := func(t *testing.T, target string) (*NamespaceWatcher, *test.Hook) { ctx, cancel := context.WithCancel(context.Background()) @@ -223,15 +206,13 @@ func TestNamespaceProvider(t *testing.T) { // write malformed, force file update require.NoError(t, ioutil.WriteFile(fn, []byte(`{"name":123,"id":"malformed"}`), 0600)) - runWithTimeOut(t, 100*time.Millisecond, func(t *testing.T) { - for { - files := ws.NamespaceFiles() - assert.Equal(t, 1, len(files)) - assert.NotNil(t, files[0].namespace) - if strings.Contains(string(files[0].Contents), "malformed") { // recieved update - break - } - } - }) + done, err := ws.w.DispatchNow() + require.NoError(t, err) + <-done + + files := ws.NamespaceFiles() + assert.Equal(t, 1, len(files)) + assert.NotNil(t, files[0].namespace) + assert.Contains(t, string(files[0].Contents), "malformed") }) }