Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5c1bf1d

Browse files
test(coderd/database): use seperate context for subtests to fix flake (#19029)
Fixes flakes likehttps://github.com/coder/coder/actions/runs/16487670478/job/46615625141, caused by the issue described inhttps://coder.com/blog/go-testing-contexts-and-t-parallelIt'd be cool if we could lint for this? That a context from an outer test isn't used in a subtest if that subtest calls `t.Parallel`.
1 parent9a05b46 commit5c1bf1d

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.WaitShort)
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.WaitShort)
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.WaitShort)
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.WaitShort)
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.WaitShort)
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
funcTestConnectionLogsOffsetFilters(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:=rangetestCases {
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)

[8]ページ先頭

©2009-2025 Movatter.jp