Skip to content

Commit

Permalink
chore: fix TestDiscoverModules flakiness
Browse files Browse the repository at this point in the history
I didn't figure out why it was being flaky, but I stable sorted
everything anyway which will fix this and any other flakiness related to
it.
  • Loading branch information
alecthomas committed Sep 27, 2024
1 parent da270ae commit 43efd35
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
41 changes: 29 additions & 12 deletions internal/buildengine/discover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ func TestDiscoverModules(t *testing.T) {
Language: "go",
Realm: "home",
Module: "alpha",
Deploy: []string{"main", "launch"},
Deploy: []string{"launch", "main"},
DeployDir: ".ftl",
Schema: "schema.pb",
Errors: "errors.pb",
Watch: []string{"**/*.go", "go.mod", "go.sum", "../../../../go-runtime/ftl/**/*.go"},
Watch: []string{
"**/*.go",
"../../../../go-runtime/ftl/**/*.go",
"go.mod",
"go.sum",
},
},
},
{
Expand All @@ -34,11 +39,17 @@ func TestDiscoverModules(t *testing.T) {
Language: "go",
Realm: "home",
Module: "another",
Deploy: []string{"main", "launch"},
Deploy: []string{"launch", "main"},
DeployDir: ".ftl",
Schema: "schema.pb",
Errors: "errors.pb",
Watch: []string{"**/*.go", "go.mod", "go.sum", "../../../../go-runtime/ftl/**/*.go", "../../../../go-runtime/schema/testdata/**/*.go"},
Watch: []string{
"**/*.go",
"../../../../go-runtime/ftl/**/*.go",
"../../../../go-runtime/schema/testdata/**/*.go",
"go.mod",
"go.sum",
},
},
},
{
Expand All @@ -47,7 +58,7 @@ func TestDiscoverModules(t *testing.T) {
Language: "go",
Realm: "home",
Module: "depcycle1",
Deploy: []string{"main", "launch"},
Deploy: []string{"launch", "main"},
DeployDir: ".ftl",
Schema: "schema.pb",
Errors: "errors.pb",
Expand All @@ -60,7 +71,7 @@ func TestDiscoverModules(t *testing.T) {
Language: "go",
Realm: "home",
Module: "depcycle2",
Deploy: []string{"main", "launch"},
Deploy: []string{"launch", "main"},
DeployDir: ".ftl",
Schema: "schema.pb",
Errors: "errors.pb",
Expand All @@ -75,8 +86,8 @@ func TestDiscoverModules(t *testing.T) {
Module: "echo",
Build: "mvn -B package",
Deploy: []string{
"quarkus-app",
"launch",
"quarkus-app",
},
DeployDir: "target",
GeneratedSchemaDir: "src/main/ftl-module-schema",
Expand All @@ -100,8 +111,8 @@ func TestDiscoverModules(t *testing.T) {
Module: "external",
Build: "",
Deploy: []string{
"main",
"launch",
"main",
},
DeployDir: ".ftl",
Schema: "schema.pb",
Expand All @@ -121,8 +132,8 @@ func TestDiscoverModules(t *testing.T) {
Module: "externalkotlin",
Build: "mvn -B package",
Deploy: []string{
"quarkus-app",
"launch",
"quarkus-app",
},
DeployDir: "target",
GeneratedSchemaDir: "src/main/ftl-module-schema",
Expand All @@ -144,7 +155,7 @@ func TestDiscoverModules(t *testing.T) {
Language: "go",
Realm: "home",
Module: "integer",
Deploy: []string{"main", "launch"},
Deploy: []string{"launch", "main"},
DeployDir: ".ftl",
Schema: "schema.pb",
Errors: "errors.pb",
Expand All @@ -157,11 +168,17 @@ func TestDiscoverModules(t *testing.T) {
Language: "go",
Realm: "home",
Module: "other",
Deploy: []string{"main", "launch"},
Deploy: []string{"launch", "main"},
DeployDir: ".ftl",
Schema: "schema.pb",
Errors: "errors.pb",
Watch: []string{"**/*.go", "go.mod", "go.sum", "../../../../go-runtime/ftl/**/*.go", "../../../../go-runtime/schema/testdata/**/*.go"},
Watch: []string{
"**/*.go",
"../../../../go-runtime/ftl/**/*.go",
"../../../../go-runtime/schema/testdata/**/*.go",
"go.mod",
"go.sum",
},
},
},
}
Expand Down
3 changes: 2 additions & 1 deletion internal/moduleconfig/moduleconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ func setConfigDefaults(moduleDir string, config *ModuleConfig) error {
return fmt.Errorf("deploy %s files must be relative to the module directory %s", deploy, moduleDir)
}
}

config.Deploy = slices.Sort(config.Deploy)
config.Watch = slices.Sort(config.Watch)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/slices/slices.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func AppendOrReplace[T any](slice []T, value T, fn func(T) bool) []T {
func Sort[T cmp.Ordered](slice []T) []T {
out := make([]T, len(slice))
copy(out, slice)
sort.Slice(out, func(i, j int) bool {
sort.SliceStable(out, func(i, j int) bool {
return out[i] < out[j]
})
return out
Expand Down

0 comments on commit 43efd35

Please sign in to comment.