Skip to content

Commit

Permalink
Fix flaky initialize handler tests (#1883)
Browse files Browse the repository at this point in the history
* Wait on state creation for discover events

* Use correct capabilities for workspace folders in tests

* Add changelog
  • Loading branch information
dbanck authored Dec 2, 2024
1 parent c1f90c8 commit e4971fd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/INTERNAL-20241202-134258.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: INTERNAL
body: Fix flaky initialize handler tests
time: 2024-12-02T13:42:58.677986+01:00
custom:
Issue: "1883"
Repository: terraform-ls
4 changes: 3 additions & 1 deletion internal/features/modules/modules_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ func (f *ModulesFeature) Start(ctx context.Context) {
ctx, cancelFunc := context.WithCancel(ctx)
f.stopFunc = cancelFunc

discover := f.eventbus.OnDiscover("feature.modules", nil)
discoverDone := make(chan job.IDs, 10)
discover := f.eventbus.OnDiscover("feature.modules", discoverDone)

didOpenDone := make(chan job.IDs, 10)
didOpen := f.eventbus.OnDidOpen("feature.modules", didOpenDone)
Expand All @@ -90,6 +91,7 @@ func (f *ModulesFeature) Start(ctx context.Context) {
case discover := <-discover:
// TODO? collect errors
f.discover(discover.Path, discover.Files)
discoverDone <- job.IDs{}
case didOpen := <-didOpen:
// TODO? collect errors
spawnedIds, _ := f.didOpen(didOpen.Context, didOpen.Dir, didOpen.LanguageID)
Expand Down
4 changes: 3 additions & 1 deletion internal/features/rootmodules/root_modules_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ func (f *RootModulesFeature) Start(ctx context.Context) {
ctx, cancelFunc := context.WithCancel(ctx)
f.stopFunc = cancelFunc

discover := f.eventbus.OnDiscover("feature.rootmodules", nil)
discoverDone := make(chan job.IDs, 10)
discover := f.eventbus.OnDiscover("feature.rootmodules", discoverDone)

didOpenDone := make(chan job.IDs, 10)
didOpen := f.eventbus.OnDidOpen("feature.rootmodules", didOpenDone)
Expand All @@ -86,6 +87,7 @@ func (f *RootModulesFeature) Start(ctx context.Context) {
case discover := <-discover:
// TODO? collect errors
f.discover(discover.Path, discover.Files)
discoverDone <- job.IDs{}
case didOpen := <-didOpen:
// TODO? collect errors
spawnedIds, _ := f.didOpen(didOpen.Context, didOpen.Dir)
Expand Down
6 changes: 5 additions & 1 deletion internal/langserver/handlers/initialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,11 @@ func TestInitialize_differentWorkspaceLayouts(t *testing.T) {
ls.Call(t, &langserver.CallRequest{
Method: "initialize",
ReqParams: fmt.Sprintf(`{
"capabilities": {},
"capabilities": {
"workspace": {
"workspaceFolders": true
}
},
"rootUri": %q,
"processId": 12345,
"workspaceFolders": [
Expand Down

0 comments on commit e4971fd

Please sign in to comment.