Skip to content

Commit d965c5e

Browse files
committed
Increase timeouts for go race tests
Signed-off-by: Charlie Egan <[email protected]>
1 parent 6470983 commit d965c5e

9 files changed

+70
-184
lines changed

internal/lsp/race_off.go

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//go:build !race
2+
// +build !race
3+
4+
package lsp
5+
6+
func isRaceEnabled() bool {
7+
return false
8+
}

internal/lsp/race_on.go

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//go:build race
2+
// +build race
3+
4+
package lsp
5+
6+
func isRaceEnabled() bool {
7+
return true
8+
}

internal/lsp/server.go

-2
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ func (l *LanguageServer) StartDiagnosticsWorker(ctx context.Context) {
237237
case <-ctx.Done():
238238
return
239239
case job := <-l.lintFileJobs:
240-
fmt.Fprintln(l.errorLog, "file", filepath.Base(job.URI), job.Reason)
241240
bis := l.builtinsForCurrentCapabilities()
242241

243242
// updateParse will not return an error when the parsing failed,
@@ -321,7 +320,6 @@ func (l *LanguageServer) StartDiagnosticsWorker(ctx context.Context) {
321320
case <-ctx.Done():
322321
return
323322
case job := <-workspaceLintRuns:
324-
fmt.Fprintln(l.errorLog, "workspace", job.Reason)
325323
err := updateAllDiagnostics(
326324
ctx,
327325
l.cache,

internal/lsp/server_aggregates_test.go

+28-169
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,12 @@ import rego.v1
7676

7777
tempDir := t.TempDir()
7878

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

84-
for f := range ls.cache.GetAllFiles() {
85-
t.Log("file loaded: ", f)
86-
}
87-
88-
t.Log("queue", len(ls.lintWorkspaceJobs))
89-
90-
timeout := time.NewTimer(defaultTimeout)
84+
timeout := time.NewTimer(determineTimeout())
9185
defer timeout.Stop()
9286

9387
// no unresolved-imports at this stage
@@ -111,65 +105,27 @@ import rego.v1
111105
}
112106
}
113107

114-
t.Log("queue", len(ls.lintWorkspaceJobs))
115-
116108
barURI := fileURIScheme + filepath.Join(tempDir, "bar.rego")
117109

118-
contentUpdate1 := `package qux
119-
120-
import rego.v1
121-
`
122-
123110
err = connClient.Call(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
124111
TextDocument: types.TextDocumentIdentifier{
125112
URI: barURI,
126113
},
127114
ContentChanges: []types.TextDocumentContentChangeEvent{
128115
{
129-
Text: contentUpdate1,
116+
Text: `package qux
117+
118+
import rego.v1
119+
`,
130120
},
131121
},
132122
}, nil)
133123
if err != nil {
134124
t.Fatalf("failed to send didChange notification: %s", err)
135125
}
136126

137-
t.Log("queue", len(ls.lintWorkspaceJobs))
138-
139-
// wait for content to have been updated
140-
timeout.Reset(defaultTimeout)
141-
142-
ticker := time.NewTicker(500 * time.Millisecond)
143-
144-
for {
145-
var success bool
146-
select {
147-
case <-ticker.C:
148-
contents, ok := ls.cache.GetFileContents(barURI)
149-
if !ok {
150-
t.Log("waiting, bar.rego contents missing")
151-
152-
continue
153-
}
154-
155-
if contents != contentUpdate1 {
156-
t.Log("waiting, bar.rego contents not yet updated")
157-
158-
continue
159-
}
160-
161-
success = true
162-
case <-timeout.C:
163-
t.Fatalf("timed out waiting bar.rego content to have been updated")
164-
}
165-
166-
if success {
167-
break
168-
}
169-
}
170-
171127
// unresolved-imports is now expected
172-
timeout.Reset(defaultTimeout)
128+
timeout.Reset(determineTimeout())
173129

174130
for {
175131
var success bool
@@ -193,60 +149,28 @@ import rego.v1
193149

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

196-
contentUpdate2 := `package foo
197-
198-
import rego.v1
199-
200-
import data.baz
201-
import data.qux # new name for bar.rego package
202-
`
203-
204152
err = connClient.Call(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
205153
TextDocument: types.TextDocumentIdentifier{
206154
URI: fooURI,
207155
},
208156
ContentChanges: []types.TextDocumentContentChangeEvent{
209157
{
210-
Text: contentUpdate2,
158+
Text: `package foo
159+
160+
import rego.v1
161+
162+
import data.baz
163+
import data.qux # new name for bar.rego package
164+
`,
211165
},
212166
},
213167
}, nil)
214168
if err != nil {
215169
t.Fatalf("failed to send didChange notification: %s", err)
216170
}
217171

218-
// wait for content to have been updated
219-
timeout.Reset(defaultTimeout)
220-
221-
for {
222-
var success bool
223-
select {
224-
case <-ticker.C:
225-
contents, ok := ls.cache.GetFileContents(fooURI)
226-
if !ok {
227-
t.Log("waiting, foo.rego contents missing")
228-
229-
continue
230-
}
231-
232-
if contents != contentUpdate2 {
233-
t.Log("waiting, foo.rego contents not yet updated")
234-
235-
continue
236-
}
237-
238-
success = true
239-
case <-timeout.C:
240-
t.Fatalf("timed out waiting foo.rego content to have been updated")
241-
}
242-
243-
if success {
244-
break
245-
}
246-
}
247-
248172
// unresolved-imports is again not expected
249-
timeout.Reset(defaultTimeout)
173+
timeout.Reset(determineTimeout())
250174

251175
for {
252176
var success bool
@@ -309,7 +233,7 @@ import data.quz
309233
}
310234

311235
// 1. check the Aggregates are set at start up
312-
timeout := time.NewTimer(defaultTimeout)
236+
timeout := time.NewTimer(determineTimeout())
313237

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

401-
timeout.Reset(defaultTimeout)
325+
timeout.Reset(determineTimeout())
402326

403327
for {
404328
success := false
@@ -490,7 +414,7 @@ import rego.v1
490414
}
491415

492416
// wait for foo.rego to have the correct violations
493-
timeout := time.NewTimer(defaultTimeout)
417+
timeout := time.NewTimer(determineTimeout())
494418
defer timeout.Stop()
495419

496420
for {
@@ -515,59 +439,26 @@ import rego.v1
515439

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

523443
err = connClient.Call(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
524444
TextDocument: types.TextDocumentIdentifier{
525445
URI: barURI,
526446
},
527447
ContentChanges: []types.TextDocumentContentChangeEvent{
528448
{
529-
Text: contentUpdate1,
449+
Text: `package bax # package imported in foo.rego
450+
451+
import rego.v1
452+
`,
530453
},
531454
},
532455
}, nil)
533456
if err != nil {
534457
t.Fatalf("failed to send didChange notification: %s", err)
535458
}
536459

537-
// wait for bar.rego to have the correct content
538-
timeout.Reset(defaultTimeout)
539-
540-
ticker := time.NewTicker(500 * time.Millisecond)
541-
542-
for {
543-
var success bool
544-
select {
545-
case <-ticker.C:
546-
contents, ok := ls.cache.GetFileContents(barURI)
547-
if !ok {
548-
t.Log("waiting, bar.rego contents missing")
549-
550-
continue
551-
}
552-
553-
if contents != contentUpdate1 {
554-
t.Log("waiting, bar.rego contents not yet updated")
555-
556-
continue
557-
}
558-
559-
success = true
560-
case <-timeout.C:
561-
t.Fatalf("timed out waiting bar.rego content to have been updated")
562-
}
563-
564-
if success {
565-
break
566-
}
567-
}
568-
569460
// wait for foo.rego to have the correct violations
570-
timeout.Reset(defaultTimeout)
461+
timeout.Reset(determineTimeout())
571462

572463
for {
573464
var success bool
@@ -589,58 +480,26 @@ import rego.v1
589480
}
590481
}
591482

592-
contentUpdate2 := `package bar # original package to bring back the violation
593-
594-
import rego.v1
595-
`
596-
597483
// update the contents of the bar.rego to bring back the violation
598484
err = connClient.Call(ctx, "textDocument/didChange", types.TextDocumentDidChangeParams{
599485
TextDocument: types.TextDocumentIdentifier{
600486
URI: barURI,
601487
},
602488
ContentChanges: []types.TextDocumentContentChangeEvent{
603489
{
604-
Text: contentUpdate2,
490+
Text: `package bar # original package to bring back the violation
491+
492+
import rego.v1
493+
`,
605494
},
606495
},
607496
}, nil)
608497
if err != nil {
609498
t.Fatalf("failed to send didChange notification: %s", err)
610499
}
611500

612-
// wait for bar.rego to have the correct content
613-
timeout.Reset(defaultTimeout)
614-
615-
for {
616-
var success bool
617-
select {
618-
case <-ticker.C:
619-
contents, ok := ls.cache.GetFileContents(barURI)
620-
if !ok {
621-
t.Log("waiting, bar.rego contents missing")
622-
623-
continue
624-
}
625-
626-
if contents != contentUpdate2 {
627-
t.Log("waiting, bar.rego contents not yet updated")
628-
629-
continue
630-
}
631-
632-
success = true
633-
case <-timeout.C:
634-
t.Fatalf("timed out waiting bar.rego content to have been updated")
635-
}
636-
637-
if success {
638-
break
639-
}
640-
}
641-
642501
// check the violation is back
643-
timeout.Reset(defaultTimeout)
502+
timeout.Reset(determineTimeout())
644503

645504
for {
646505
var success bool

internal/lsp/server_config_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ allow := true
8383
t.Fatalf("expected client root URI to be %s, got %s", exp, got)
8484
}
8585

86-
timeout := time.NewTimer(defaultTimeout)
86+
timeout := time.NewTimer(determineTimeout())
8787
defer timeout.Stop()
8888

8989
for {
@@ -117,7 +117,7 @@ allow := true
117117
}
118118

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

122122
for {
123123
var success bool

internal/lsp/server_multi_file_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ ignore:
9999
}
100100

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

105105
for {
@@ -123,7 +123,7 @@ ignore:
123123
}
124124

125125
// validate that the client received a diagnostics notification admins.rego
126-
timeout.Reset(defaultTimeout)
126+
timeout.Reset(determineTimeout())
127127

128128
for {
129129
var success bool
@@ -173,7 +173,7 @@ allow if input.user in admins.users
173173
}
174174

175175
// authz.rego should now have no violations
176-
timeout.Reset(defaultTimeout)
176+
timeout.Reset(determineTimeout())
177177

178178
for {
179179
var success bool

0 commit comments

Comments
 (0)