Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lsp: Address test concurrency issues #1112

Merged
merged 3 commits into from
Sep 17, 2024

Conversation

charlieegan3
Copy link
Member

@charlieegan3 charlieegan3 commented Sep 16, 2024

This PR is intended to address two issues with the test suite that happen when running tests concurrently:

TestLanguageServerSingleFile fails sometimes as the server logs an error when the context has been cancelled, and it's a panic when logging to t, after the test is over.

https://github.com/StyraInc/regal/actions/runs/10875806798/job/30174833322

TestGetInlayHintsAstTerms will fail when TestLanguageServerSingleFile is running sometimes as TestLanguageServerSingleFile updates the contents of the map while TestGetInlayHintsAstTerms is iterating over it.

https://github.com/StyraInc/regal/actions/runs/10875806798/job/30184826633

Coincidentally, both these issues happened on a recent community PR, which underlines the importance of addressing these as they're a bad contributor experience.

This PR also includes, in a second commit 554f612, an update to rego.QueryRegalBundle to accept a context. See commit message, but there appears to be a recurring issue here where tests timeout.

IO have updated the function an callers to pass a context to this function to allow us to better understand this issue.

@@ -23,7 +24,7 @@ func GetBuiltins() map[string]*ast.Builtin {
builtInsLock.RLock()
defer builtInsLock.RUnlock()

return builtIns
return maps.Clone(builtIns)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to what we have in the cache, we return a copy instead.

@@ -56,6 +56,8 @@ func LocationFromPosition(pos types.Position) *ast.Location {
func AllBuiltinCalls(module *ast.Module) []BuiltInCall {
builtinCalls := make([]BuiltInCall, 0)

bis := GetBuiltins()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading the builtins once also seemed like a good plan here since we're now loading a copy.

tl.mu.Lock()
defer tl.mu.Unlock()
tl.open = false
})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the test is over, the logger is closed to stop it accepting more logs and causing a panic when the test is done.

@charlieegan3 charlieegan3 force-pushed the address-test-issues branch 2 times, most recently from edcc758 to af6fa23 Compare September 16, 2024 14:54
This PR is intended to address two issues with the test suite that
happen when running tests concurrently:

TestLanguageServerSingleFile fails sometimes as the server logs an error
when the context has been cancelled, and it's a panic when logging to t,
after the test is over.

https://github.com/StyraInc/regal/actions/runs/10875806798/job/30174833322

TestGetInlayHintsAstTerms will fail when TestLanguageServerSingleFile is
running sometimes as TestLanguageServerSingleFile updates the contents
of the map while TestGetInlayHintsAstTerms is iterating over it.

https://github.com/StyraInc/regal/actions/runs/10875806798/job/30184826633

Signed-off-by: Charlie Egan <[email protected]>
There are cases where the tests timeout running `rego.QueryRegalBundle`:

Here are two from today:

https://github.com/StyraInc/regal/actions/runs/10883075294/job/30195419440

https://github.com/StyraInc/regal/actions/runs/10883075932/job/30195421353

My hope is that we can use a cancelled context to avoid this and see what the
real issue is, if there is one.

Signed-off-by: Charlie Egan <[email protected]>
@@ -5,6 +5,8 @@ import (
"strings"
"testing"

"golang.org/x/net/context"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be used anymore, probably an auto import

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, thanks, have added a new commit to address

Copy link
Member

@srenatus srenatus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@charlieegan3
Copy link
Member Author

Thanks Stephan, appreciate the review here 🙏

@charlieegan3 charlieegan3 merged commit 06734bb into StyraInc:main Sep 17, 2024
4 checks passed
charlieegan3 added a commit to charlieegan3/regal that referenced this pull request Sep 24, 2024
Built ins must now be provided by the caller.

We have been having a number of issues where the shared list of builtins
was required to be in a different state in different tests.

Related
StyraInc#1101
StyraInc#1102
StyraInc#1112
StyraInc#1121
StyraInc#1129

Signed-off-by: Charlie Egan <[email protected]>
charlieegan3 added a commit to charlieegan3/regal that referenced this pull request Sep 24, 2024
Built ins must now be provided by the caller.

We have been having a number of issues where the shared list of builtins
was required to be in a different state in different tests.

Related
StyraInc#1101
StyraInc#1102
StyraInc#1112
StyraInc#1121
StyraInc#1129

Signed-off-by: Charlie Egan <[email protected]>
charlieegan3 added a commit to charlieegan3/regal that referenced this pull request Sep 24, 2024
Built ins must now be provided by the caller.

We have been having a number of issues where the shared list of builtins
was required to be in a different state in different tests.

Related
StyraInc#1101
StyraInc#1102
StyraInc#1112
StyraInc#1121
StyraInc#1129

Signed-off-by: Charlie Egan <[email protected]>
charlieegan3 added a commit to charlieegan3/regal that referenced this pull request Sep 24, 2024
Built ins must now be provided by the caller.

We have been having a number of issues where the shared list of builtins
was required to be in a different state in different tests.

Related
StyraInc#1101
StyraInc#1102
StyraInc#1112
StyraInc#1121
StyraInc#1129

Signed-off-by: Charlie Egan <[email protected]>
charlieegan3 added a commit to charlieegan3/regal that referenced this pull request Sep 24, 2024
Built ins must now be provided by the caller.

We have been having a number of issues where the shared list of builtins
was required to be in a different state in different tests.

Related
StyraInc#1101
StyraInc#1102
StyraInc#1112
StyraInc#1121
StyraInc#1129

Signed-off-by: Charlie Egan <[email protected]>
anderseknert pushed a commit that referenced this pull request Sep 24, 2024
Built ins must now be provided by the caller.

We have been having a number of issues where the shared list of builtins
was required to be in a different state in different tests.

Related
#1101
#1102
#1112
#1121
#1129

Signed-off-by: Charlie Egan <[email protected]>
srenatus pushed a commit to srenatus/regal that referenced this pull request Oct 1, 2024
* lsp: Address test concurrency issues

This PR is intended to address two issues with the test suite that
happen when running tests concurrently:

TestLanguageServerSingleFile fails sometimes as the server logs an error
when the context has been cancelled, and it's a panic when logging to t,
after the test is over.

https://github.com/StyraInc/regal/actions/runs/10875806798/job/30174833322

TestGetInlayHintsAstTerms will fail when TestLanguageServerSingleFile is
running sometimes as TestLanguageServerSingleFile updates the contents
of the map while TestGetInlayHintsAstTerms is iterating over it.

https://github.com/StyraInc/regal/actions/runs/10875806798/job/30184826633

Signed-off-by: Charlie Egan <[email protected]>

* lsp: Pass ctx when querying the Regal bundle

There are cases where the tests timeout running `rego.QueryRegalBundle`:

Here are two from today:

https://github.com/StyraInc/regal/actions/runs/10883075294/job/30195419440

https://github.com/StyraInc/regal/actions/runs/10883075932/job/30195421353

My hope is that we can use a cancelled context to avoid this and see what the
real issue is, if there is one.

Signed-off-by: Charlie Egan <[email protected]>

* tests: Drop old context import

Signed-off-by: Charlie Egan <[email protected]>

---------

Signed-off-by: Charlie Egan <[email protected]>
srenatus pushed a commit to srenatus/regal that referenced this pull request Oct 1, 2024
Built ins must now be provided by the caller.

We have been having a number of issues where the shared list of builtins
was required to be in a different state in different tests.

Related
StyraInc#1101
StyraInc#1102
StyraInc#1112
StyraInc#1121
StyraInc#1129

Signed-off-by: Charlie Egan <[email protected]>
charlieegan3 added a commit to charlieegan3/regal that referenced this pull request Jan 6, 2025
* lsp: Address test concurrency issues

This PR is intended to address two issues with the test suite that
happen when running tests concurrently:

TestLanguageServerSingleFile fails sometimes as the server logs an error
when the context has been cancelled, and it's a panic when logging to t,
after the test is over.

https://github.com/StyraInc/regal/actions/runs/10875806798/job/30174833322

TestGetInlayHintsAstTerms will fail when TestLanguageServerSingleFile is
running sometimes as TestLanguageServerSingleFile updates the contents
of the map while TestGetInlayHintsAstTerms is iterating over it.

https://github.com/StyraInc/regal/actions/runs/10875806798/job/30184826633

Signed-off-by: Charlie Egan <[email protected]>

* lsp: Pass ctx when querying the Regal bundle

There are cases where the tests timeout running `rego.QueryRegalBundle`:

Here are two from today:

https://github.com/StyraInc/regal/actions/runs/10883075294/job/30195419440

https://github.com/StyraInc/regal/actions/runs/10883075932/job/30195421353

My hope is that we can use a cancelled context to avoid this and see what the
real issue is, if there is one.

Signed-off-by: Charlie Egan <[email protected]>

* tests: Drop old context import

Signed-off-by: Charlie Egan <[email protected]>

---------

Signed-off-by: Charlie Egan <[email protected]>
charlieegan3 added a commit to charlieegan3/regal that referenced this pull request Jan 6, 2025
Built ins must now be provided by the caller.

We have been having a number of issues where the shared list of builtins
was required to be in a different state in different tests.

Related
StyraInc#1101
StyraInc#1102
StyraInc#1112
StyraInc#1121
StyraInc#1129

Signed-off-by: Charlie Egan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants