Skip to content

Commit

Permalink
tests: Address incorrect built-in function check (#1129)
Browse files Browse the repository at this point in the history
Signed-off-by: Charlie Egan <charlie@styra.com>
  • Loading branch information
charlieegan3 authored Sep 23, 2024
1 parent d41bea9 commit 4aa2fef
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions internal/lsp/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,30 +336,29 @@ capabilities:
}
}

// NOTE(charles): the configuration is updated asynchronously from the
// thread the test is running in. This check prevents a race condition
// where the completion test runs before rego.builtIns is updated which
// was causing flaky tests in CI.
// manually inspect the server's list of builtins to ensure that the EOPA
// capabilities were loaded correctly.
timeout = time.NewTimer(defaultTimeout)
defer timeout.Stop()

ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()

for {
success := false

select {
case <-timeout.C:
t.Fatalf("timed out waiting for builtins map to be updated")
default:
case <-ticker.C:
bis := rego.GetBuiltins()

// Search for a builtin we know is only in the EOPA capabilities.
if _, ok := bis["startswith"]; ok {
if _, ok := bis["neo4j.query"]; ok {
success = true
} else {
// If we hammer the mutex too hard, it may never
// get a chance to be updated.
time.Sleep(100 * time.Millisecond)
}

t.Logf("waiting for neo4j.query builtin to be present, got %v", bis)
}

if success {
Expand Down Expand Up @@ -426,7 +425,7 @@ allow := neo4j.q
timeout = time.NewTimer(defaultTimeout)
defer timeout.Stop()

ticker := time.NewTicker(100 * time.Millisecond)
ticker = time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()

for {
Expand Down

0 comments on commit 4aa2fef

Please sign in to comment.