Skip to content

Commit d5746db

Browse files
Fix failing tests due to wrong context
1 parent 0294a93 commit d5746db

6 files changed

Lines changed: 5 additions & 40 deletions

File tree

AGENTS.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,7 @@ log.Errorf(ctx, "...")
206206
```
207207

208208
Note that the 'ctx' variable here is something that should be passed in as
209-
<<<<<<< HEAD
210209
an argument by the caller.
211-
=======
212-
an argument by the caller. In tests, use `t.Context()` (or `b.Context()` for benchmarks) instead of `context.Background()`. This is enforced by a lint rule.
213-
>>>>>>> 47d9694f3 (Use t.Context() instead of context.Background() in tests (#4655))
214210

215211
Use cmdio.LogString to print to stdout:
216212

NEXT_CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
### Bundles
88
* Added permissions support for Lakebase Database projects ([#4626](https://github.com/databricks/cli/pull/4626))
9-
* Validate that either source_code_path or git_source is set for apps ([#4632](https://github.com/databricks/cli/pull/4632))
10-
* direct: model_serving_endpoints: ignore budget_policy_id, rate_limits changes in the plan. Previously they were ignored as well but action as "update". ([#4638](https://github.com/databricks/cli/pull/4638))
119

1210
### Dependency updates
1311

cmd/auth/logout_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package auth
22

33
import (
4-
"context"
54
"os"
65
"path/filepath"
76
"testing"
@@ -161,7 +160,7 @@ func TestLogout(t *testing.T) {
161160

162161
for _, tc := range cases {
163162
t.Run(tc.name, func(t *testing.T) {
164-
ctx := cmdio.MockDiscard(context.Background())
163+
ctx := cmdio.MockDiscard(t.Context())
165164
configPath := writeTempConfig(t, logoutTestConfig)
166165
t.Setenv("DATABRICKS_CONFIG_FILE", configPath)
167166

@@ -204,7 +203,7 @@ func TestLogout(t *testing.T) {
204203
}
205204

206205
func TestLogoutNoTokens(t *testing.T) {
207-
ctx := cmdio.MockDiscard(context.Background())
206+
ctx := cmdio.MockDiscard(t.Context())
208207
configPath := writeTempConfig(t, logoutTestConfig)
209208
t.Setenv("DATABRICKS_CONFIG_FILE", configPath)
210209

@@ -228,7 +227,7 @@ func TestLogoutNoTokens(t *testing.T) {
228227
}
229228

230229
func TestLogoutNoTokensWithDelete(t *testing.T) {
231-
ctx := cmdio.MockDiscard(context.Background())
230+
ctx := cmdio.MockDiscard(t.Context())
232231
configPath := writeTempConfig(t, logoutTestConfig)
233232
t.Setenv("DATABRICKS_CONFIG_FILE", configPath)
234233

libs/databrickscfg/ops_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ host = https://only.cloud.databricks.com
341341

342342
for _, tc := range cases {
343343
t.Run(tc.name, func(t *testing.T) {
344-
ctx := context.Background()
344+
ctx := t.Context()
345345
path := filepath.Join(t.TempDir(), ".databrickscfg")
346346
require.NoError(t, os.WriteFile(path, []byte(tc.seedConfig), fileMode))
347347

@@ -367,7 +367,7 @@ host = https://only.cloud.databricks.com
367367
}
368368

369369
func TestDeleteProfile_NotFound(t *testing.T) {
370-
ctx := context.Background()
370+
ctx := t.Context()
371371
path := filepath.Join(t.TempDir(), ".databrickscfg")
372372
require.NoError(t, os.WriteFile(path, []byte(""), fileMode))
373373

libs/filer/workspace_files_cache_test.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ func TestWorkspaceFilesCache_ReadDirCache(t *testing.T) {
8181
}
8282

8383
ctx := t.Context()
84-
<<<<<<< HEAD
8584
cache := newWorkspaceFilesReadaheadCache(ctx, f)
86-
=======
87-
cache := newWorkspaceFilesReadaheadCache(f)
88-
>>>>>>> 47d9694f3 (Use t.Context() instead of context.Background() in tests (#4655))
8985
defer cache.Cleanup()
9086

9187
// First read dir should hit the filer, second should hit the cache.
@@ -126,11 +122,7 @@ func TestWorkspaceFilesCache_ReadDirCacheIsolation(t *testing.T) {
126122
}
127123

128124
ctx := t.Context()
129-
<<<<<<< HEAD
130125
cache := newWorkspaceFilesReadaheadCache(ctx, f)
131-
=======
132-
cache := newWorkspaceFilesReadaheadCache(f)
133-
>>>>>>> 47d9694f3 (Use t.Context() instead of context.Background() in tests (#4655))
134126
defer cache.Cleanup()
135127

136128
// First read dir should hit the filer, second should hit the cache.
@@ -161,11 +153,7 @@ func TestWorkspaceFilesCache_StatCache(t *testing.T) {
161153
}
162154

163155
ctx := t.Context()
164-
<<<<<<< HEAD
165156
cache := newWorkspaceFilesReadaheadCache(ctx, f)
166-
=======
167-
cache := newWorkspaceFilesReadaheadCache(f)
168-
>>>>>>> 47d9694f3 (Use t.Context() instead of context.Background() in tests (#4655))
169157
defer cache.Cleanup()
170158

171159
// First stat should hit the filer, second should hit the cache.
@@ -234,11 +222,7 @@ func TestWorkspaceFilesCache_ReadDirPopulatesStatCache(t *testing.T) {
234222
}
235223

236224
ctx := t.Context()
237-
<<<<<<< HEAD
238225
cache := newWorkspaceFilesReadaheadCache(ctx, f)
239-
=======
240-
cache := newWorkspaceFilesReadaheadCache(f)
241-
>>>>>>> 47d9694f3 (Use t.Context() instead of context.Background() in tests (#4655))
242226
defer cache.Cleanup()
243227

244228
// Issue read dir to populate the stat cache.
@@ -305,11 +289,7 @@ func TestWorkspaceFilesCache_ReadDirTriggersReadahead(t *testing.T) {
305289
}
306290

307291
ctx := t.Context()
308-
<<<<<<< HEAD
309292
cache := newWorkspaceFilesReadaheadCache(ctx, f)
310-
=======
311-
cache := newWorkspaceFilesReadaheadCache(f)
312-
>>>>>>> 47d9694f3 (Use t.Context() instead of context.Background() in tests (#4655))
313293
defer cache.Cleanup()
314294

315295
// Issue read dir to populate the stat cache.

libs/gorules/rule_context_background.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,9 @@ package gorules
22

33
import "github.com/quasilyte/go-ruleguard/dsl"
44

5-
<<<<<<< HEAD
65
// NoContextBackground detects context.Background() outside of main.go files.
76
func NoContextBackground(m dsl.Matcher) {
87
m.Match(`context.Background()`).
98
Where(!m.File().Name.Matches(`^main\.go$`)).
109
Report(`Do not use context.Background(); use t.Context() in tests or pass context from caller`)
11-
=======
12-
// UseTestContext detects context.Background() in test files and suggests using t.Context().
13-
func UseTestContext(m dsl.Matcher) {
14-
m.Match(`context.Background()`).
15-
Where(m.File().Name.Matches(`_test\.go$`)).
16-
Report(`Use t.Context() or b.Context() in tests instead of context.Background()`)
17-
>>>>>>> 47d9694f3 (Use t.Context() instead of context.Background() in tests (#4655))
1810
}

0 commit comments

Comments
 (0)