Skip to content

Commit

Permalink
Increase timeouts for go race tests
Browse files Browse the repository at this point in the history
Signed-off-by: Charlie Egan <[email protected]>
  • Loading branch information
charlieegan3 committed Oct 2, 2024
1 parent 238e314 commit dfd0b39
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 184 deletions.
8 changes: 8 additions & 0 deletions internal/lsp/race_off.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build !race
// +build !race

package lsp

func isRaceEnabled() bool {
return false
}
8 changes: 8 additions & 0 deletions internal/lsp/race_on.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build race
// +build race

package lsp

func isRaceEnabled() bool {
return true
}
2 changes: 0 additions & 2 deletions internal/lsp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ func (l *LanguageServer) StartDiagnosticsWorker(ctx context.Context) {
case <-ctx.Done():
return
case job := <-l.lintFileJobs:
fmt.Fprintln(l.errorLog, "file", filepath.Base(job.URI), job.Reason)
bis := l.builtinsForCurrentCapabilities()

// updateParse will not return an error when the parsing failed,
Expand Down Expand Up @@ -321,7 +320,6 @@ func (l *LanguageServer) StartDiagnosticsWorker(ctx context.Context) {
case <-ctx.Done():
return
case job := <-workspaceLintRuns:
fmt.Fprintln(l.errorLog, "workspace", job.Reason)
err := updateAllDiagnostics(
ctx,
l.cache,
Expand Down
197 changes: 28 additions & 169 deletions internal/lsp/server_aggregates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,12 @@ import rego.v1

tempDir := t.TempDir()

ls, connClient, err := createAndInitServer(ctx, newTestLogger(t), tempDir, files, clientHandler)
_, connClient, err := createAndInitServer(ctx, newTestLogger(t), tempDir, files, clientHandler)
if err != nil {
t.Fatalf("failed to create and init language server: %s", err)
}

for f := range ls.cache.GetAllFiles() {
t.Log("file loaded: ", f)
}

t.Log("queue", len(ls.lintWorkspaceJobs))

timeout := time.NewTimer(defaultTimeout)
timeout := time.NewTimer(determineTimeout())
defer timeout.Stop()

// no unresolved-imports at this stage
Expand All @@ -111,65 +105,27 @@ import rego.v1
}
}

t.Log("queue", len(ls.lintWorkspaceJobs))

barURI := fileURIScheme + filepath.Join(tempDir, "bar.rego")

contentUpdate1 := `package qux
import rego.v1
`

err = connClient.Call(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
TextDocument: types.TextDocumentIdentifier{
URI: barURI,
},
ContentChanges: []types.TextDocumentContentChangeEvent{
{
Text: contentUpdate1,
Text: `package qux
import rego.v1
`,
},
},
}, nil)
if err != nil {
t.Fatalf("failed to send didChange notification: %s", err)
}

t.Log("queue", len(ls.lintWorkspaceJobs))

// wait for content to have been updated
timeout.Reset(defaultTimeout)

ticker := time.NewTicker(500 * time.Millisecond)

for {
var success bool
select {
case <-ticker.C:
contents, ok := ls.cache.GetFileContents(barURI)
if !ok {
t.Log("waiting, bar.rego contents missing")

continue
}

if contents != contentUpdate1 {
t.Log("waiting, bar.rego contents not yet updated")

continue
}

success = true
case <-timeout.C:
t.Fatalf("timed out waiting bar.rego content to have been updated")
}

if success {
break
}
}

// unresolved-imports is now expected
timeout.Reset(defaultTimeout)
timeout.Reset(determineTimeout())

for {
var success bool
Expand All @@ -193,60 +149,28 @@ import rego.v1

fooURI := fileURIScheme + filepath.Join(tempDir, "foo.rego")

contentUpdate2 := `package foo
import rego.v1
import data.baz
import data.qux # new name for bar.rego package
`

err = connClient.Call(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
TextDocument: types.TextDocumentIdentifier{
URI: fooURI,
},
ContentChanges: []types.TextDocumentContentChangeEvent{
{
Text: contentUpdate2,
Text: `package foo
import rego.v1
import data.baz
import data.qux # new name for bar.rego package
`,
},
},
}, nil)
if err != nil {
t.Fatalf("failed to send didChange notification: %s", err)
}

// wait for content to have been updated
timeout.Reset(defaultTimeout)

for {
var success bool
select {
case <-ticker.C:
contents, ok := ls.cache.GetFileContents(fooURI)
if !ok {
t.Log("waiting, foo.rego contents missing")

continue
}

if contents != contentUpdate2 {
t.Log("waiting, foo.rego contents not yet updated")

continue
}

success = true
case <-timeout.C:
t.Fatalf("timed out waiting foo.rego content to have been updated")
}

if success {
break
}
}

// unresolved-imports is again not expected
timeout.Reset(defaultTimeout)
timeout.Reset(determineTimeout())

for {
var success bool
Expand Down Expand Up @@ -309,7 +233,7 @@ import data.quz
}

// 1. check the Aggregates are set at start up
timeout := time.NewTimer(defaultTimeout)
timeout := time.NewTimer(determineTimeout())

ticker := time.NewTicker(500 * time.Millisecond)
defer ticker.Stop()
Expand Down Expand Up @@ -398,7 +322,7 @@ import data.wow # new
t.Fatalf("failed to send didChange notification: %s", err)
}

timeout.Reset(defaultTimeout)
timeout.Reset(determineTimeout())

for {
success := false
Expand Down Expand Up @@ -490,7 +414,7 @@ import rego.v1
}

// wait for foo.rego to have the correct violations
timeout := time.NewTimer(defaultTimeout)
timeout := time.NewTimer(determineTimeout())
defer timeout.Stop()

for {
Expand All @@ -515,59 +439,26 @@ import rego.v1

// update the contents of the bar.rego file to address the unresolved-import
barURI := fileURIScheme + filepath.Join(tempDir, "bar.rego")
contentUpdate1 := `package bax # package imported in foo.rego
import rego.v1
`

err = connClient.Call(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
TextDocument: types.TextDocumentIdentifier{
URI: barURI,
},
ContentChanges: []types.TextDocumentContentChangeEvent{
{
Text: contentUpdate1,
Text: `package bax # package imported in foo.rego
import rego.v1
`,
},
},
}, nil)
if err != nil {
t.Fatalf("failed to send didChange notification: %s", err)
}

// wait for bar.rego to have the correct content
timeout.Reset(defaultTimeout)

ticker := time.NewTicker(500 * time.Millisecond)

for {
var success bool
select {
case <-ticker.C:
contents, ok := ls.cache.GetFileContents(barURI)
if !ok {
t.Log("waiting, bar.rego contents missing")

continue
}

if contents != contentUpdate1 {
t.Log("waiting, bar.rego contents not yet updated")

continue
}

success = true
case <-timeout.C:
t.Fatalf("timed out waiting bar.rego content to have been updated")
}

if success {
break
}
}

// wait for foo.rego to have the correct violations
timeout.Reset(defaultTimeout)
timeout.Reset(determineTimeout())

for {
var success bool
Expand All @@ -589,58 +480,26 @@ import rego.v1
}
}

contentUpdate2 := `package bar # original package to bring back the violation
import rego.v1
`

// update the contents of the bar.rego to bring back the violation
err = connClient.Call(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
TextDocument: types.TextDocumentIdentifier{
URI: barURI,
},
ContentChanges: []types.TextDocumentContentChangeEvent{
{
Text: contentUpdate2,
Text: `package bar # original package to bring back the violation
import rego.v1
`,
},
},
}, nil)
if err != nil {
t.Fatalf("failed to send didChange notification: %s", err)
}

// wait for bar.rego to have the correct content
timeout.Reset(defaultTimeout)

for {
var success bool
select {
case <-ticker.C:
contents, ok := ls.cache.GetFileContents(barURI)
if !ok {
t.Log("waiting, bar.rego contents missing")

continue
}

if contents != contentUpdate2 {
t.Log("waiting, bar.rego contents not yet updated")

continue
}

success = true
case <-timeout.C:
t.Fatalf("timed out waiting bar.rego content to have been updated")
}

if success {
break
}
}

// check the violation is back
timeout.Reset(defaultTimeout)
timeout.Reset(determineTimeout())

for {
var success bool
Expand Down
4 changes: 2 additions & 2 deletions internal/lsp/server_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ allow := true
t.Fatalf("expected client root URI to be %s, got %s", exp, got)
}

timeout := time.NewTimer(defaultTimeout)
timeout := time.NewTimer(determineTimeout())
defer timeout.Stop()

for {
Expand Down Expand Up @@ -117,7 +117,7 @@ allow := true
}

// validate that the client received a new, empty diagnostics notification for the file
timeout.Reset(defaultTimeout)
timeout.Reset(determineTimeout())

for {
var success bool
Expand Down
6 changes: 3 additions & 3 deletions internal/lsp/server_multi_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ignore:
}

// validate that the client received a diagnostics notification for authz.rego
timeout := time.NewTimer(defaultTimeout)
timeout := time.NewTimer(determineTimeout())
defer timeout.Stop()

for {
Expand All @@ -123,7 +123,7 @@ ignore:
}

// validate that the client received a diagnostics notification admins.rego
timeout.Reset(defaultTimeout)
timeout.Reset(determineTimeout())

for {
var success bool
Expand Down Expand Up @@ -173,7 +173,7 @@ allow if input.user in admins.users
}

// authz.rego should now have no violations
timeout.Reset(defaultTimeout)
timeout.Reset(determineTimeout())

for {
var success bool
Expand Down
Loading

0 comments on commit dfd0b39

Please sign in to comment.