Jan Kühnlein
12/30/2024, 8:02 PMfunc waitForCerbos(t *testing.T, c *cerbos.GRPCClient) {
assert.Eventually(t, func() bool {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
_, err := c.ServerInfo(ctx)
return err == nil
}, 10*time.Second, 100*time.Millisecond)
}
The test server is started with:
s, err := testutil.LaunchCerbosServer(ctx, testutil.LaunchConf{
PolicyDir: policyPath,
})
Any ideas or maybe I’m missing something?Charith (Cerbos)
NewCerbosServerLauncher with your own readiness check. If that works, that's absolutely fine too. The LaunchCerbosServer function is just for convenience anyway.Jan Kühnlein
01/01/2025, 10:03 AMCharith (Cerbos)
func LaunchCerbosServer(t *testing.T, launchConf testutil.LaunchConf) *cerbos.GRPCClient {
t.Helper()
launcher, err := testutil.NewCerbosServerLauncher()
require.NoError(t, err)
server, err := launcher.Launch(launchConf)
require.NoError(t, err)
t.Cleanup(func() { _ = server.Stop() })
client, err := cerbos.New("passthrough:///"+server.GRPCAddr(), cerbos.WithPlaintext())
require.NoError(t, err)
require.EventuallyWithT(t, func(c *assert.CollectT) {
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel()
_, err := client.ServerInfo(ctx)
assert.NoError(c, err)
}, 10*time.Second, 150*time.Millisecond)
return client
}