-
Notifications
You must be signed in to change notification settings - Fork 37
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
Conversation
@@ -23,7 +24,7 @@ func GetBuiltins() map[string]*ast.Builtin { | |||
builtInsLock.RLock() | |||
defer builtInsLock.RUnlock() | |||
|
|||
return builtIns | |||
return maps.Clone(builtIns) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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 | ||
}) |
There was a problem hiding this comment.
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.
edcc758
to
af6fa23
Compare
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]>
af6fa23
to
6a46f50
Compare
@@ -5,6 +5,8 @@ import ( | |||
"strings" | |||
"testing" | |||
|
|||
"golang.org/x/net/context" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Signed-off-by: Charlie Egan <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks Stephan, appreciate the review here 🙏 |
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]>
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]>
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]>
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]>
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]>
* 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]>
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]>
* 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]>
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]>
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.