Skip to content

Commit 7fa5288

Browse files
committed
test(coderd/database): use seperate context for subtests to fix flake
1 parent 9a05b46 commit 7fa5288

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

coderd/database/querier_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,7 +2037,6 @@ func TestAuthorizedAuditLogs(t *testing.T) {
20372037
}
20382038

20392039
// Now fetch all the logs
2040-
ctx := testutil.Context(t, testutil.WaitLong)
20412040
auditorRole, err := rbac.RoleByName(rbac.RoleAuditor())
20422041
require.NoError(t, err)
20432042

@@ -2054,6 +2053,7 @@ func TestAuthorizedAuditLogs(t *testing.T) {
20542053

20552054
t.Run("NoAccess", func(t *testing.T) {
20562055
t.Parallel()
2056+
ctx := testutil.Context(t, testutil.WaitShort)
20572057

20582058
// Given: A user who is a member of 0 organizations
20592059
memberCtx := dbauthz.As(ctx, rbac.Subject{
@@ -2076,6 +2076,7 @@ func TestAuthorizedAuditLogs(t *testing.T) {
20762076

20772077
t.Run("SiteWideAuditor", func(t *testing.T) {
20782078
t.Parallel()
2079+
ctx := testutil.Context(t, testutil.WaitShort)
20792080

20802081
// Given: A site wide auditor
20812082
siteAuditorCtx := dbauthz.As(ctx, rbac.Subject{
@@ -2098,6 +2099,7 @@ func TestAuthorizedAuditLogs(t *testing.T) {
20982099

20992100
t.Run("SingleOrgAuditor", func(t *testing.T) {
21002101
t.Parallel()
2102+
ctx := testutil.Context(t, testutil.WaitShort)
21012103

21022104
orgID := orgIDs[0]
21032105
// Given: An organization scoped auditor
@@ -2121,6 +2123,7 @@ func TestAuthorizedAuditLogs(t *testing.T) {
21212123

21222124
t.Run("TwoOrgAuditors", func(t *testing.T) {
21232125
t.Parallel()
2126+
ctx := testutil.Context(t, testutil.WaitShort)
21242127

21252128
first := orgIDs[0]
21262129
second := orgIDs[1]
@@ -2147,6 +2150,7 @@ func TestAuthorizedAuditLogs(t *testing.T) {
21472150

21482151
t.Run("ErroneousOrg", func(t *testing.T) {
21492152
t.Parallel()
2153+
ctx := testutil.Context(t, testutil.WaitShort)
21502154

21512155
// Given: A user who is an auditor for an organization that has 0 logs
21522156
userCtx := dbauthz.As(ctx, rbac.Subject{
@@ -2232,7 +2236,6 @@ func TestGetAuthorizedConnectionLogsOffset(t *testing.T) {
22322236
}
22332237

22342238
// Now fetch all the logs
2235-
ctx := testutil.Context(t, testutil.WaitLong)
22362239
auditorRole, err := rbac.RoleByName(rbac.RoleAuditor())
22372240
require.NoError(t, err)
22382241

@@ -2249,6 +2252,7 @@ func TestGetAuthorizedConnectionLogsOffset(t *testing.T) {
22492252

22502253
t.Run("NoAccess", func(t *testing.T) {
22512254
t.Parallel()
2255+
ctx := testutil.Context(t, testutil.WaitLong)
22522256

22532257
// Given: A user who is a member of 0 organizations
22542258
memberCtx := dbauthz.As(ctx, rbac.Subject{
@@ -2271,6 +2275,7 @@ func TestGetAuthorizedConnectionLogsOffset(t *testing.T) {
22712275

22722276
t.Run("SiteWideAuditor", func(t *testing.T) {
22732277
t.Parallel()
2278+
ctx := testutil.Context(t, testutil.WaitLong)
22742279

22752280
// Given: A site wide auditor
22762281
siteAuditorCtx := dbauthz.As(ctx, rbac.Subject{
@@ -2293,6 +2298,7 @@ func TestGetAuthorizedConnectionLogsOffset(t *testing.T) {
22932298

22942299
t.Run("SingleOrgAuditor", func(t *testing.T) {
22952300
t.Parallel()
2301+
ctx := testutil.Context(t, testutil.WaitLong)
22962302

22972303
orgID := orgIDs[0]
22982304
// Given: An organization scoped auditor
@@ -2316,6 +2322,7 @@ func TestGetAuthorizedConnectionLogsOffset(t *testing.T) {
23162322

23172323
t.Run("TwoOrgAuditors", func(t *testing.T) {
23182324
t.Parallel()
2325+
ctx := testutil.Context(t, testutil.WaitLong)
23192326

23202327
first := orgIDs[0]
23212328
second := orgIDs[1]
@@ -2340,6 +2347,7 @@ func TestGetAuthorizedConnectionLogsOffset(t *testing.T) {
23402347

23412348
t.Run("ErroneousOrg", func(t *testing.T) {
23422349
t.Parallel()
2350+
ctx := testutil.Context(t, testutil.WaitLong)
23432351

23442352
// Given: A user who is an auditor for an organization that has 0 logs
23452353
userCtx := dbauthz.As(ctx, rbac.Subject{
@@ -2421,7 +2429,6 @@ func TestCountConnectionLogs(t *testing.T) {
24212429

24222430
func TestConnectionLogsOffsetFilters(t *testing.T) {
24232431
t.Parallel()
2424-
ctx := testutil.Context(t, testutil.WaitLong)
24252432

24262433
db, _ := dbtestutil.NewDB(t)
24272434

@@ -2652,9 +2659,9 @@ func TestConnectionLogsOffsetFilters(t *testing.T) {
26522659
}
26532660

26542661
for _, tc := range testCases {
2655-
tc := tc
26562662
t.Run(tc.name, func(t *testing.T) {
26572663
t.Parallel()
2664+
ctx := testutil.Context(t, testutil.WaitLong)
26582665
logs, err := db.GetConnectionLogsOffset(ctx, tc.params)
26592666
require.NoError(t, err)
26602667
count, err := db.CountConnectionLogs(ctx, database.CountConnectionLogsParams{

0 commit comments

Comments
 (0)