From c2e0bcd9254655004b99e1b5ed3189fedcd7c461 Mon Sep 17 00:00:00 2001 From: Philip Conrad Date: Fri, 18 Oct 2024 17:54:33 -0400 Subject: [PATCH] test: Parallelize package level tests in high-cost packages. This commit adds `t.Parallel()` calls to the beginning of many tests across several Go packages in OPA. The slowest packages (taking ~10s or more) have been instrumented where possible as a proof-of-concept. On a machine with many cores, the tests now will complete as fast as the slowest test per package, instead of the sum of all the tests in a particular package. Background: Go runs tests across different packages in parallel, but will run all tests *within* a package sequentially. By adding `t.Parallel()` to tests that support it, we are telling the test-runner that it is safe to run that test in parallel with any other tests. Signed-off-by: Philip Conrad --- cmd/bench_test.go | 70 +++++++++++++++- download/download_test.go | 39 +++++++++ plugins/bundle/plugin_test.go | 97 ++++++++++++++++++++- plugins/logs/plugin_test.go | 78 +++++++++++++++-- plugins/rest/rest_test.go | 62 ++++++++++++++ server/server_test.go | 153 ++++++++++++++++++++++++++++++++++ topdown/cache/cache_test.go | 24 ++++++ 7 files changed, 513 insertions(+), 10 deletions(-) diff --git a/cmd/bench_test.go b/cmd/bench_test.go index 2b22683d49..98bce011a5 100644 --- a/cmd/bench_test.go +++ b/cmd/bench_test.go @@ -26,6 +26,8 @@ import ( // Minimize the number of tests that *actually* run the benchmarks, they are pretty slow. // Have one test that exercises the whole flow. func TestRunBenchmark(t *testing.T) { + t.Parallel() + params := testBenchParams() args := []string{"1 + 1"} @@ -61,6 +63,8 @@ func TestRunBenchmark(t *testing.T) { } func TestRunBenchmarkWithQueryImport(t *testing.T) { + t.Parallel() + params := testBenchParams() // We add the rego.v1 import .. params.imports = newrepeatedStringFlag([]string{"rego.v1"}) @@ -99,6 +103,8 @@ func TestRunBenchmarkWithQueryImport(t *testing.T) { } func TestRunBenchmarkE2E(t *testing.T) { + t.Parallel() + params := testBenchParams() params.e2e = true @@ -143,6 +149,7 @@ func TestRunBenchmarkE2E(t *testing.T) { } func TestRunBenchmarkE2EWithOPAConfigFile(t *testing.T) { + t.Parallel() fs := map[string]string{ "/config.yaml": `{"decision_logs": {"console": true}}`, @@ -196,6 +203,8 @@ func TestRunBenchmarkE2EWithOPAConfigFile(t *testing.T) { } func TestRunBenchmarkFailFastE2E(t *testing.T) { + t.Parallel() + params := testBenchParams() params.fail = true // configured to fail on undefined results params.e2e = true @@ -225,6 +234,8 @@ func TestRunBenchmarkFailFastE2E(t *testing.T) { } func TestBenchPartialE2E(t *testing.T) { + t.Parallel() + params := testBenchParams() params.partial = true params.fail = true @@ -270,6 +281,8 @@ func TestBenchPartialE2E(t *testing.T) { } func TestRunBenchmarkPartialFailFastE2E(t *testing.T) { + t.Parallel() + params := testBenchParams() params.partial = true params.unknowns = []string{} @@ -300,10 +313,11 @@ func TestRunBenchmarkPartialFailFastE2E(t *testing.T) { if actual != expected { t.Fatalf("\nExpected:\n%s\n\nGot:\n%s\n", expected, actual) } - } func TestRunBenchmarkFailFast(t *testing.T) { + t.Parallel() + params := testBenchParams() params.fail = true // configured to fail on undefined results @@ -345,6 +359,8 @@ func (r *mockBenchRunner) run(ctx context.Context, ectx *evalContext, params ben } func TestBenchPartial(t *testing.T) { + t.Parallel() + params := testBenchParams() params.partial = true params.fail = true @@ -362,6 +378,8 @@ func TestBenchPartial(t *testing.T) { } func TestBenchMainErrPreparing(t *testing.T) { + t.Parallel() + params := testBenchParams() args := []string{"???"} // query compile error var buf bytes.Buffer @@ -377,6 +395,8 @@ func TestBenchMainErrPreparing(t *testing.T) { } func TestBenchMainErrRunningBenchmark(t *testing.T) { + t.Parallel() + params := testBenchParams() args := []string{"1+1"} var buf bytes.Buffer @@ -397,6 +417,8 @@ func TestBenchMainErrRunningBenchmark(t *testing.T) { } func TestBenchMainWithCount(t *testing.T) { + t.Parallel() + params := testBenchParams() args := []string{"1+1"} var buf bytes.Buffer @@ -425,6 +447,8 @@ func TestBenchMainWithCount(t *testing.T) { } func TestBenchMainWithNegativeCount(t *testing.T) { + t.Parallel() + params := testBenchParams() args := []string{"1+1"} var buf bytes.Buffer @@ -489,6 +513,8 @@ func validateBenchMainPrep(t *testing.T, args []string, params benchmarkCommandP } func TestBenchMainWithJSONInputFile(t *testing.T) { + t.Parallel() + params := testBenchParams() files := map[string]string{ "/input.json": `{"x": 42}`, @@ -502,6 +528,8 @@ func TestBenchMainWithJSONInputFile(t *testing.T) { } func TestBenchMainWithYAMLInputFile(t *testing.T) { + t.Parallel() + params := testBenchParams() files := map[string]string{ "/input.yaml": `x: 42`, @@ -515,6 +543,8 @@ func TestBenchMainWithYAMLInputFile(t *testing.T) { } func TestBenchMainInvalidInputFile(t *testing.T) { + t.Parallel() + params := testBenchParams() files := map[string]string{ "/input.yaml": `x: 42`, @@ -536,6 +566,8 @@ func TestBenchMainInvalidInputFile(t *testing.T) { } func TestBenchMainWithJSONInputFileE2E(t *testing.T) { + t.Parallel() + params := testBenchParams() params.e2e = true files := map[string]string{ @@ -559,6 +591,8 @@ func TestBenchMainWithJSONInputFileE2E(t *testing.T) { } func TestBenchMainWithYAMLInputFileE2E(t *testing.T) { + t.Parallel() + params := testBenchParams() params.e2e = true files := map[string]string{ @@ -582,6 +616,8 @@ func TestBenchMainWithYAMLInputFileE2E(t *testing.T) { } func TestBenchMainInvalidInputFileE2E(t *testing.T) { + t.Parallel() + params := testBenchParams() params.e2e = true files := map[string]string{ @@ -605,6 +641,8 @@ func TestBenchMainInvalidInputFileE2E(t *testing.T) { } func TestBenchMainWithBundleData(t *testing.T) { + t.Parallel() + params := testBenchParams() b := testBundle() @@ -637,6 +675,8 @@ func TestBenchMainWithBundleData(t *testing.T) { } func TestBenchMainWithBundleDataE2E(t *testing.T) { + t.Parallel() + params := testBenchParams() params.e2e = true @@ -679,6 +719,8 @@ func TestBenchMainWithBundleDataE2E(t *testing.T) { } func TestBenchMainWithDataE2E(t *testing.T) { + t.Parallel() + params := testBenchParams() params.e2e = true @@ -716,6 +758,8 @@ func TestBenchMainWithDataE2E(t *testing.T) { } func TestBenchMainBadQueryE2E(t *testing.T) { + t.Parallel() + params := testBenchParams() params.e2e = true args := []string{"foo.bar"} @@ -733,6 +777,8 @@ func TestBenchMainBadQueryE2E(t *testing.T) { } func TestBenchMainCompatibleFlags(t *testing.T) { + t.Parallel() + tests := []struct { note string v0Compatible bool @@ -813,7 +859,10 @@ a[4] { for _, mode := range modes { for _, tc := range tests { + tc := tc // Reassignment prevents loop var scoping issue. (See: https://go.dev/blog/loopvar-preview) t.Run(fmt.Sprintf("%s, %s", tc.note, mode.name), func(t *testing.T) { + t.Parallel() + files := map[string]string{ "mod.rego": tc.module, } @@ -863,6 +912,8 @@ a[4] { } func TestBenchMainWithBundleRegoVersion(t *testing.T) { + t.Parallel() + tests := []struct { note string bundleRegoVersion int @@ -972,7 +1023,10 @@ a contains 4 if { for _, bundleType := range bundleTypeCases { for _, mode := range modes { for _, tc := range tests { + tc := tc // Reassignment prevents loop var scoping issue. (See: https://go.dev/blog/loopvar-preview) t.Run(fmt.Sprintf("%s, %s, %s", bundleType.note, tc.note, mode.name), func(t *testing.T) { + t.Parallel() + files := map[string]string{} if bundleType.tar { @@ -1062,6 +1116,8 @@ a contains 4 if { } func TestRenderBenchmarkResultJSONOutput(t *testing.T) { + t.Parallel() + params := testBenchParams() err := params.outputFormat.Set(evalJSONOutput) if err != nil { @@ -1103,6 +1159,8 @@ func TestRenderBenchmarkResultJSONOutput(t *testing.T) { } func TestRenderBenchmarkResultPrettyOutput(t *testing.T) { + t.Parallel() + params := testBenchParams() params.benchMem = false err := params.outputFormat.Set(evalPrettyOutput) @@ -1140,6 +1198,8 @@ func TestRenderBenchmarkResultPrettyOutput(t *testing.T) { } func TestRenderBenchmarkResultPrettyOutputShowAllocs(t *testing.T) { + t.Parallel() + params := testBenchParams() params.benchMem = true err := params.outputFormat.Set(evalPrettyOutput) @@ -1179,6 +1239,8 @@ func TestRenderBenchmarkResultPrettyOutputShowAllocs(t *testing.T) { } func TestRenderBenchmarkResultGoBenchOutputShowAllocs(t *testing.T) { + t.Parallel() + params := testBenchParams() params.benchMem = true err := params.outputFormat.Set(benchmarkGoBenchOutput) @@ -1203,6 +1265,8 @@ func TestRenderBenchmarkResultGoBenchOutputShowAllocs(t *testing.T) { } func TestRenderBenchmarkErrorJSONOutput(t *testing.T) { + t.Parallel() + params := testBenchParams() err := params.outputFormat.Set(evalJSONOutput) if err != nil { @@ -1244,6 +1308,8 @@ func TestRenderBenchmarkErrorJSONOutput(t *testing.T) { } func TestRenderBenchmarkErrorPrettyOutput(t *testing.T) { + t.Parallel() + params := testBenchParams() err := params.outputFormat.Set(evalPrettyOutput) if err != nil { @@ -1254,6 +1320,8 @@ func TestRenderBenchmarkErrorPrettyOutput(t *testing.T) { } func TestRenderBenchmarkErrorGoBenchOutput(t *testing.T) { + t.Parallel() + params := testBenchParams() err := params.outputFormat.Set(benchmarkGoBenchOutput) if err != nil { diff --git a/download/download_test.go b/download/download_test.go index 2dea57b842..c9a4bcd896 100644 --- a/download/download_test.go +++ b/download/download_test.go @@ -25,6 +25,8 @@ import ( ) func TestStartStop(t *testing.T) { + t.Parallel() + ctx := context.Background() fixture := newTestFixture(t) @@ -62,6 +64,8 @@ func TestStartStop(t *testing.T) { } func TestStartStopWithBundlePersistence(t *testing.T) { + t.Parallel() + ctx := context.Background() fixture := newTestFixture(t) @@ -118,6 +122,8 @@ func TestStartStopWithBundlePersistence(t *testing.T) { } func TestStopWithMultipleCalls(t *testing.T) { + t.Parallel() + ctx := context.Background() fixture := newTestFixture(t) @@ -158,6 +164,8 @@ func TestStopWithMultipleCalls(t *testing.T) { } func TestStartStopWithLazyLoadingMode(t *testing.T) { + t.Parallel() + ctx := context.Background() fixture := newTestFixture(t) @@ -199,6 +207,8 @@ func TestStartStopWithLazyLoadingMode(t *testing.T) { } func TestStartStopWithDeltaBundleMode(t *testing.T) { + t.Parallel() + ctx := context.Background() updates := make(chan *Update) @@ -234,6 +244,8 @@ func TestStartStopWithDeltaBundleMode(t *testing.T) { } func TestStartStopWithLongPollNotSupported(t *testing.T) { + t.Parallel() + ctx := context.Background() config := Config{} @@ -264,6 +276,8 @@ func TestStartStopWithLongPollNotSupported(t *testing.T) { } func TestStartStopWithLongPollSupportedByServer(t *testing.T) { + t.Parallel() + ctx := context.Background() config := Config{} @@ -300,6 +314,8 @@ func TestStartStopWithLongPollSupportedByServer(t *testing.T) { } func TestStartStopWithLongPollSupported(t *testing.T) { + t.Parallel() + ctx := context.Background() config := Config{} @@ -327,6 +343,8 @@ func TestStartStopWithLongPollSupported(t *testing.T) { } func TestStartStopWithLongPollWithLongTimeout(t *testing.T) { + t.Parallel() + ctx := context.Background() config := Config{} @@ -362,6 +380,7 @@ func TestStartStopWithLongPollWithLongTimeout(t *testing.T) { } func TestEtagCachingLifecycle(t *testing.T) { + t.Parallel() ctx := context.Background() fixture := newTestFixture(t) @@ -456,6 +475,7 @@ func TestEtagCachingLifecycle(t *testing.T) { } func TestOneShotWithBundleEtag(t *testing.T) { + t.Parallel() ctx := context.Background() fixture := newTestFixture(t) @@ -490,6 +510,8 @@ func TestOneShotWithBundleEtag(t *testing.T) { } func TestOneShotV1Compatible(t *testing.T) { + t.Parallel() + tests := []struct { note string v1Compatible bool @@ -590,6 +612,8 @@ func TestOneShotV1Compatible(t *testing.T) { } func TestOneShotWithBundleRegoVersion(t *testing.T) { + t.Parallel() + tests := []struct { note string bundleRegoVersion int @@ -719,6 +743,7 @@ p contains 1 if { } func TestFailureAuthn(t *testing.T) { + t.Parallel() ctx := context.Background() fixture := newTestFixture(t) @@ -734,6 +759,7 @@ func TestFailureAuthn(t *testing.T) { } func TestFailureNotFound(t *testing.T) { + t.Parallel() ctx := context.Background() fixture := newTestFixture(t) @@ -749,6 +775,7 @@ func TestFailureNotFound(t *testing.T) { } func TestFailureUnexpected(t *testing.T) { + t.Parallel() ctx := context.Background() fixture := newTestFixture(t) @@ -771,6 +798,7 @@ func TestFailureUnexpected(t *testing.T) { } func TestFailureUnexpectedWithResponseBody(t *testing.T) { + t.Parallel() ctx := context.Background() @@ -816,6 +844,8 @@ func TestFailureUnexpectedWithResponseBody(t *testing.T) { } func TestEtagInResponse(t *testing.T) { + t.Parallel() + ctx := context.Background() fixture := newTestFixture(t) fixture.server.etagInResponse = true @@ -858,6 +888,7 @@ func TestEtagInResponse(t *testing.T) { } func TestTriggerManual(t *testing.T) { + t.Parallel() ctx := context.Background() fixture := newTestFixture(t) @@ -905,6 +936,7 @@ func TestTriggerManual(t *testing.T) { } func TestTriggerManualWithTimeout(t *testing.T) { + t.Parallel() ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) defer cancel() @@ -952,6 +984,7 @@ func TestTriggerManualWithTimeout(t *testing.T) { } func TestDownloadLongPollNotModifiedOn304(t *testing.T) { + t.Parallel() ctx := context.Background() config := Config{} @@ -980,6 +1013,8 @@ func TestDownloadLongPollNotModifiedOn304(t *testing.T) { } func TestOneShotLongPollingSwitch(t *testing.T) { + t.Parallel() + ctx := context.Background() config := Config{} timeout := int64(3) // this will result in the test server sleeping for 3 seconds @@ -1012,6 +1047,8 @@ func TestOneShotLongPollingSwitch(t *testing.T) { } func TestOneShotNotLongPollingSwitch(t *testing.T) { + t.Parallel() + ctx := context.Background() config := Config{} timeout := int64(3) @@ -1045,6 +1082,8 @@ func TestOneShotNotLongPollingSwitch(t *testing.T) { } func TestWarnOnNonBundleContentType(t *testing.T) { + t.Parallel() + ctx := context.Background() fixture := newTestFixture(t) fixture.server.bundles["not-a-bundle"] = bundle.Bundle{} diff --git a/plugins/bundle/plugin_test.go b/plugins/bundle/plugin_test.go index 4650689f73..62169c426e 100644 --- a/plugins/bundle/plugin_test.go +++ b/plugins/bundle/plugin_test.go @@ -46,6 +46,7 @@ const ( ) func TestPluginOneShot(t *testing.T) { + t.Parallel() ctx := context.Background() manager := getTestManager() @@ -113,6 +114,7 @@ func TestPluginOneShot(t *testing.T) { } func TestPluginOneShotWithAstStore(t *testing.T) { + t.Parallel() ctx := context.Background() store := inmem.NewWithOpts(inmem.OptRoundTripOnWrite(false), inmem.OptReturnASTValuesOnRead(true)) @@ -157,6 +159,8 @@ func TestPluginOneShotWithAstStore(t *testing.T) { } func TestPluginOneShotV1Compatible(t *testing.T) { + t.Parallel() + // Note: modules are parsed before passed to plugin, so any expected errors must be triggered by the compiler stage. tests := []struct { note string @@ -296,6 +300,8 @@ corge contains 1 if { } func TestPluginOneShotWithBundleRegoVersion(t *testing.T) { + t.Parallel() + // Note: modules are parsed before passed to plugin, so any expected errors must be triggered by the compiler stage. tests := []struct { note string @@ -542,6 +548,7 @@ corge contains 1 if { } func TestPluginOneShotWithAuthzSchemaVerification(t *testing.T) { + t.Parallel() ctx := context.Background() @@ -686,6 +693,7 @@ func TestPluginOneShotWithAuthzSchemaVerification(t *testing.T) { } func TestPluginOneShotWithAuthzSchemaVerificationNonDefaultAuthzPath(t *testing.T) { + t.Parallel() ctx := context.Background() @@ -785,6 +793,8 @@ func TestPluginOneShotWithAuthzSchemaVerificationNonDefaultAuthzPath(t *testing. } func TestPluginStartLazyLoadInMem(t *testing.T) { + t.Parallel() + readMode := []struct { note string readAst bool @@ -967,6 +977,7 @@ func TestPluginStartLazyLoadInMem(t *testing.T) { } func TestPluginOneShotDiskStorageMetrics(t *testing.T) { + t.Parallel() test.WithTempFS(nil, func(dir string) { ctx := context.Background() @@ -1072,6 +1083,7 @@ func TestPluginOneShotDiskStorageMetrics(t *testing.T) { } func TestPluginOneShotDeltaBundle(t *testing.T) { + t.Parallel() ctx := context.Background() manager := getTestManager() @@ -1169,6 +1181,7 @@ func TestPluginOneShotDeltaBundle(t *testing.T) { } func TestPluginOneShotDeltaBundleWithAstStore(t *testing.T) { + t.Parallel() ctx := context.Background() store := inmem.NewWithOpts(inmem.OptRoundTripOnWrite(false), inmem.OptReturnASTValuesOnRead(true)) @@ -1267,6 +1280,7 @@ func TestPluginOneShotDeltaBundleWithAstStore(t *testing.T) { } func TestPluginStart(t *testing.T) { + t.Parallel() ctx := context.Background() manager := getTestManager() @@ -1280,6 +1294,8 @@ func TestPluginStart(t *testing.T) { } func TestStop(t *testing.T) { + t.Parallel() + var longPollTimeout int64 = 3 done := make(chan struct{}) tsURLBase := "/opa-test/" @@ -1345,6 +1361,7 @@ func TestStop(t *testing.T) { } func TestPluginOneShotBundlePersistence(t *testing.T) { + t.Parallel() ctx := context.Background() manager := getTestManager() @@ -1446,6 +1463,8 @@ func TestPluginOneShotBundlePersistence(t *testing.T) { } func TestPluginOneShotBundlePersistenceV1Compatible(t *testing.T) { + t.Parallel() + // Note: modules are parsed before passed to plugin, so any expected errors must be triggered by the compiler stage. tests := []struct { note string @@ -1631,6 +1650,8 @@ corge contains 1 if { } func TestPluginOneShotBundlePersistenceWithBundleRegoVersion(t *testing.T) { + t.Parallel() + // Note: modules are parsed before passed to plugin, so any expected errors must be triggered by the compiler stage. tests := []struct { note string @@ -1923,6 +1944,7 @@ corge contains 1 if { } func TestPluginOneShotSignedBundlePersistence(t *testing.T) { + t.Parallel() ctx := context.Background() manager := getTestManager() @@ -2019,6 +2041,7 @@ func TestPluginOneShotSignedBundlePersistence(t *testing.T) { } func TestLoadAndActivateBundlesFromDisk(t *testing.T) { + t.Parallel() ctx := context.Background() manager := getTestManager() @@ -2100,6 +2123,7 @@ func TestLoadAndActivateBundlesFromDisk(t *testing.T) { } func TestLoadAndActivateBundlesFromDiskReservedChars(t *testing.T) { + t.Parallel() ctx := context.Background() manager := getTestManager() @@ -2179,6 +2203,8 @@ func TestLoadAndActivateBundlesFromDiskReservedChars(t *testing.T) { } func TestLoadAndActivateBundlesFromDiskV1Compatible(t *testing.T) { + t.Parallel() + type update struct { modules map[string]string expErrs []string @@ -2426,6 +2452,8 @@ corge contains 2 if { } func TestLoadAndActivateBundlesFromDiskWithBundleRegoVersion(t *testing.T) { + t.Parallel() + // Note: modules are parsed before passed to plugin, so any expected errors must be triggered by the compiler stage. tests := []struct { note string @@ -2654,6 +2682,8 @@ func bundleRegoVersion(v ast.RegoVersion) int { } func TestLoadAndActivateDepBundlesFromDisk(t *testing.T) { + t.Parallel() + ctx := context.Background() manager := getTestManager() @@ -2760,6 +2790,8 @@ is_one(x) if { } func TestLoadAndActivateDepBundlesFromDiskMaxAttempts(t *testing.T) { + t.Parallel() + ctx := context.Background() manager := getTestManager() @@ -2827,6 +2859,7 @@ allow if { } func TestPluginOneShotCompileError(t *testing.T) { + t.Parallel() ctx := context.Background() manager := getTestManager() @@ -2916,10 +2949,11 @@ p contains x`), if err != nil || !reflect.DeepEqual("b", data) { t.Fatalf("Expected data to be intact but got: %v, err: %v", data, err) } - } func TestPluginOneShotHTTPError(t *testing.T) { + t.Parallel() + ctx := context.Background() manager := getTestManager() plugin := New(&Config{}, manager) @@ -2959,6 +2993,7 @@ func TestPluginOneShotHTTPError(t *testing.T) { } func TestPluginOneShotActivationRemovesOld(t *testing.T) { + t.Parallel() ctx := context.Background() manager := getTestManager() @@ -3030,13 +3065,14 @@ func TestPluginOneShotActivationRemovesOld(t *testing.T) { } return nil }) - if err != nil { t.Fatal("Unexpected:", err) } } func TestPluginOneShotActivationConflictingRoots(t *testing.T) { + t.Parallel() + ctx := context.Background() manager := getTestManager() plugin := New(&Config{}, manager) @@ -3104,6 +3140,8 @@ func TestPluginOneShotActivationConflictingRoots(t *testing.T) { } func TestPluginOneShotActivationPrefixMatchingRoots(t *testing.T) { + t.Parallel() + ctx := context.Background() manager := getTestManager() plugin := Plugin{ @@ -3141,7 +3179,6 @@ func TestPluginOneShotActivationPrefixMatchingRoots(t *testing.T) { }}) ensureBundleOverlapStatus(t, &plugin, bundleNames, []bool{false, true}) - } func ensureBundleOverlapStatus(t *testing.T, p *Plugin, bundleNames []string, expectedErrs []bool) { @@ -3159,6 +3196,7 @@ func ensureBundleOverlapStatus(t *testing.T, p *Plugin, bundleNames []string, ex } func TestPluginListener(t *testing.T) { + t.Parallel() ctx := context.Background() manager := getTestManager() @@ -3272,6 +3310,8 @@ func validateStatus(t *testing.T, actual Status, expected string, expectStatusEr } func TestPluginListenerErrorClearedOn304(t *testing.T) { + t.Parallel() + ctx := context.Background() manager := getTestManager() plugin := Plugin{ @@ -3324,6 +3364,8 @@ func TestPluginListenerErrorClearedOn304(t *testing.T) { } func TestPluginBulkListener(t *testing.T) { + t.Parallel() + ctx := context.Background() manager := getTestManager() plugin := Plugin{ @@ -3525,6 +3567,8 @@ p contains x if { x = 1 }` } func TestPluginBulkListenerStatusCopyOnly(t *testing.T) { + t.Parallel() + ctx := context.Background() manager := getTestManager() plugin := Plugin{ @@ -3584,6 +3628,8 @@ p contains x if { x = 1 }` } func TestPluginActivateScopedBundle(t *testing.T) { + t.Parallel() + readMode := []struct { note string readAst bool @@ -3744,6 +3790,7 @@ func TestPluginActivateScopedBundle(t *testing.T) { } func TestPluginSetCompilerOnContext(t *testing.T) { + t.Parallel() ctx := context.Background() manager := getTestManager() @@ -3822,6 +3869,8 @@ func getTestManagerWithOpts(config []byte, stores ...storage.Store) *plugins.Man } func TestPluginReconfigure(t *testing.T) { + t.Parallel() + tsURLBase := "/opa-test/" ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if !strings.HasPrefix(r.URL.Path, tsURLBase) { @@ -4019,6 +4068,7 @@ func TestPluginReconfigure(t *testing.T) { } func TestPluginRequestVsDownloadTimestamp(t *testing.T) { + t.Parallel() ctx := context.Background() manager := getTestManager() @@ -4068,6 +4118,7 @@ func TestPluginRequestVsDownloadTimestamp(t *testing.T) { } func TestUpgradeLegacyBundleToMuiltiBundleSameBundle(t *testing.T) { + t.Parallel() ctx := context.Background() manager := getTestManager() @@ -4164,6 +4215,8 @@ func TestUpgradeLegacyBundleToMuiltiBundleSameBundle(t *testing.T) { } func TestUpgradeLegacyBundleToMultiBundleNewBundles(t *testing.T) { + t.Parallel() + ctx := context.Background() manager := getTestManager() @@ -4303,6 +4356,8 @@ func TestUpgradeLegacyBundleToMultiBundleNewBundles(t *testing.T) { } func TestLegacyBundleDataRead(t *testing.T) { + t.Parallel() + readModes := []struct { note string readAst bool @@ -4408,6 +4463,7 @@ func TestLegacyBundleDataRead(t *testing.T) { } func TestSaveBundleToDiskNew(t *testing.T) { + t.Parallel() manager := getTestManager() @@ -4424,6 +4480,8 @@ func TestSaveBundleToDiskNew(t *testing.T) { } func TestSaveBundleToDiskNewConfiguredPersistDir(t *testing.T) { + t.Parallel() + dir := t.TempDir() manager := getTestManager() @@ -4449,6 +4507,7 @@ func TestSaveBundleToDiskNewConfiguredPersistDir(t *testing.T) { } func TestSaveBundleToDiskOverWrite(t *testing.T) { + t.Parallel() manager := getTestManager() @@ -4509,6 +4568,8 @@ func TestSaveBundleToDiskOverWrite(t *testing.T) { } func TestSaveCurrentBundleToDisk(t *testing.T) { + t.Parallel() + srcDir := t.TempDir() bundlePath, err := saveCurrentBundleToDisk(srcDir, getTestRawBundle(t)) @@ -4532,6 +4593,7 @@ func TestSaveCurrentBundleToDisk(t *testing.T) { } func TestLoadBundleFromDisk(t *testing.T) { + t.Parallel() manager := getTestManager() plugin := New(&Config{}, manager) @@ -4566,6 +4628,8 @@ func TestLoadBundleFromDisk(t *testing.T) { } func TestLoadBundleFromDiskV1Compatible(t *testing.T) { + t.Parallel() + popts := ast.ParserOptions{RegoVersion: ast.RegoV1} manager, err := plugins.New(nil, "test-instance-id", inmemtst.New(), plugins.WithParserOptions(popts)) @@ -4626,6 +4690,8 @@ p contains 1 if { } func TestLoadSignedBundleFromDisk(t *testing.T) { + t.Parallel() + manager := getTestManager() plugin := New(&Config{}, manager) @@ -4667,6 +4733,8 @@ func TestLoadSignedBundleFromDisk(t *testing.T) { } func TestGetDefaultBundlePersistPath(t *testing.T) { + t.Parallel() + plugin := New(&Config{}, getTestManager()) path, err := plugin.getBundlePersistPath() if err != nil { @@ -4679,6 +4747,8 @@ func TestGetDefaultBundlePersistPath(t *testing.T) { } func TestConfiguredBundlePersistPath(t *testing.T) { + t.Parallel() + persistPath := "/var/opa" manager := getTestManager() manager.Config.PersistenceDirectory = &persistPath @@ -4695,6 +4765,7 @@ func TestConfiguredBundlePersistPath(t *testing.T) { } func TestPluginUsingFileLoader(t *testing.T) { + t.Parallel() test.WithTempFS(map[string]string{}, func(dir string) { @@ -4749,10 +4820,11 @@ func TestPluginUsingFileLoader(t *testing.T) { t.Fatal("expected successful activation") } }) - } func TestPluginUsingFileLoaderV1Compatible(t *testing.T) { + t.Parallel() + tests := []struct { note string v1Compatible bool @@ -4940,6 +5012,8 @@ p contains 7 if { } func TestPluginUsingFileLoaderWithBundleRegoVersion(t *testing.T) { + t.Parallel() + tests := []struct { note string managerRegoVersion ast.RegoVersion @@ -5255,6 +5329,8 @@ p contains 7 if { } func TestPluginUsingDirectoryLoader(t *testing.T) { + t.Parallel() + test.WithTempFS(map[string]string{ "test.rego": `package test @@ -5290,6 +5366,8 @@ func TestPluginUsingDirectoryLoader(t *testing.T) { } func TestPluginUsingDirectoryLoaderV1Compatible(t *testing.T) { + t.Parallel() + tests := []struct { note string v1Compatible bool @@ -5456,6 +5534,8 @@ p contains 7 if { } func TestPluginUsingDirectoryLoaderWithBundleRegoVersion(t *testing.T) { + t.Parallel() + tests := []struct { note string managerRegoVersion ast.RegoVersion @@ -5748,6 +5828,7 @@ p contains 7 if { } func TestPluginReadBundleEtagFromDiskStore(t *testing.T) { + t.Parallel() // setup fake http server with mock bundle mockBundle := bundle.Bundle{ @@ -5925,6 +6006,8 @@ func TestPluginReadBundleEtagFromDiskStore(t *testing.T) { } func TestPluginStateReconciliationOnReconfigure(t *testing.T) { + t.Parallel() + // setup fake http server with mock bundle mockBundles := map[string]bundle.Bundle{ "b1": { @@ -6122,6 +6205,7 @@ func TestPluginStateReconciliationOnReconfigure(t *testing.T) { } func TestPluginManualTrigger(t *testing.T) { + t.Parallel() ctx := context.Background() @@ -6210,6 +6294,7 @@ func TestPluginManualTrigger(t *testing.T) { } func TestPluginManualTriggerMultipleDiskStorage(t *testing.T) { + t.Parallel() ctx := context.Background() @@ -6359,6 +6444,7 @@ func TestPluginManualTriggerMultipleDiskStorage(t *testing.T) { } func TestPluginManualTriggerMultiple(t *testing.T) { + t.Parallel() ctx := context.Background() @@ -6463,6 +6549,7 @@ func TestPluginManualTriggerMultiple(t *testing.T) { } func TestPluginManualTriggerWithTimeout(t *testing.T) { + t.Parallel() ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) defer cancel() @@ -6523,6 +6610,8 @@ func TestPluginManualTriggerWithTimeout(t *testing.T) { } func TestGetNormalizedBundleName(t *testing.T) { + t.Parallel() + cases := []struct { input string goos string diff --git a/plugins/logs/plugin_test.go b/plugins/logs/plugin_test.go index d904205811..68295616ba 100644 --- a/plugins/logs/plugin_test.go +++ b/plugins/logs/plugin_test.go @@ -64,6 +64,8 @@ func (p *testPlugin) Log(_ context.Context, event EventV1) error { } func TestPluginCustomBackend(t *testing.T) { + t.Parallel() + ctx := context.Background() manager, _ := plugins.New(nil, "test-instance-id", inmem.New()) @@ -92,6 +94,7 @@ func TestPluginCustomBackend(t *testing.T) { } func TestPluginCustomBackendAndHTTPServiceAndConsole(t *testing.T) { + t.Parallel() ctx := context.Background() backend := testPlugin{} @@ -156,6 +159,8 @@ func TestPluginCustomBackendAndHTTPServiceAndConsole(t *testing.T) { } func TestPluginRequestContext(t *testing.T) { + t.Parallel() + ctx := context.Background() manager, _ := plugins.New(nil, "test-instance-id", inmem.New()) @@ -267,6 +272,8 @@ func TestPluginRequestContext(t *testing.T) { } func TestPluginSingleBundle(t *testing.T) { + t.Parallel() + ctx := context.Background() manager, _ := plugins.New(nil, "test-instance-id", inmem.New()) @@ -292,6 +299,8 @@ func TestPluginSingleBundle(t *testing.T) { } func TestPluginErrorNoResult(t *testing.T) { + t.Parallel() + ctx := context.Background() manager, _ := plugins.New(nil, "test-instance-id", inmem.New()) @@ -315,6 +324,8 @@ func TestPluginErrorNoResult(t *testing.T) { } func TestPluginQueriesAndPaths(t *testing.T) { + t.Parallel() + ctx := context.Background() manager, _ := plugins.New(nil, "test-instance-id", inmem.New()) @@ -362,6 +373,7 @@ func TestPluginQueriesAndPaths(t *testing.T) { } func TestPluginStartSameInput(t *testing.T) { + t.Parallel() ctx := context.Background() @@ -442,6 +454,7 @@ func TestPluginStartSameInput(t *testing.T) { } func TestPluginStartChangingInputValues(t *testing.T) { + t.Parallel() ctx := context.Background() @@ -511,6 +524,7 @@ func TestPluginStartChangingInputValues(t *testing.T) { } func TestPluginStartChangingInputKeysAndValues(t *testing.T) { + t.Parallel() ctx := context.Background() @@ -572,6 +586,7 @@ func TestPluginStartChangingInputKeysAndValues(t *testing.T) { } func TestPluginRequeue(t *testing.T) { + t.Parallel() ctx := context.Background() @@ -631,6 +646,8 @@ func logServerInfo(id string, input interface{}, result interface{}) *server.Inf } func TestPluginRequeBufferPreserved(t *testing.T) { + t.Parallel() + ctx := context.Background() fixture := newTestFixture(t, testFixtureOptions{ReportingUploadSizeLimitBytes: 300}) @@ -664,6 +681,8 @@ func TestPluginRequeBufferPreserved(t *testing.T) { } func TestPluginRateLimitInt(t *testing.T) { + t.Parallel() + ctx := context.Background() ts, err := time.Parse(time.RFC3339Nano, "2018-01-01T12:00:00.123456Z") @@ -762,6 +781,8 @@ func TestPluginRateLimitInt(t *testing.T) { } func TestPluginRateLimitFloat(t *testing.T) { + t.Parallel() + ctx := context.Background() ts, err := time.Parse(time.RFC3339Nano, "2018-01-01T12:00:00.123456Z") @@ -769,7 +790,7 @@ func TestPluginRateLimitFloat(t *testing.T) { panic(err) } - numDecisions := 0.1 // 0.1 decision per second ie. 1 decision per 10 seconds + numDecisions := 0.5 // 0.5 decision per second ie. 1 decision per 2 seconds fixture := newTestFixture(t, testFixtureOptions{ ReportingMaxDecisionsPerSecond: float64(numDecisions), ReportingUploadSizeLimitBytes: 300, @@ -810,14 +831,14 @@ func TestPluginRateLimitFloat(t *testing.T) { t.Fatalf("Expected %v bytes written into the encoder but got %v", bytesWritten, fixture.plugin.enc.bytesWritten) } - time.Sleep(5 * time.Second) + time.Sleep(1 * time.Second) _ = fixture.plugin.Log(ctx, event2) // event 2 should not be written into the encoder as rate limit exceeded if fixture.plugin.enc.bytesWritten != bytesWritten { t.Fatalf("Expected %v bytes written into the encoder but got %v", bytesWritten, fixture.plugin.enc.bytesWritten) } - time.Sleep(5 * time.Second) + time.Sleep(1 * time.Second) _ = fixture.plugin.Log(ctx, event2) // event 2 should now be written into the encoder if fixture.plugin.buffer.Len() != 1 { @@ -867,6 +888,8 @@ func TestPluginRateLimitFloat(t *testing.T) { } func TestPluginStatusUpdateHTTPError(t *testing.T) { + t.Parallel() + ctx := context.Background() fixture := newTestFixture(t, testFixtureOptions{ReportingUploadSizeLimitBytes: 300}) @@ -909,6 +932,8 @@ func TestPluginStatusUpdateHTTPError(t *testing.T) { } func TestPluginStatusUpdateEncodingFailure(t *testing.T) { + t.Parallel() + ctx := context.Background() testLogger := test.New() @@ -997,6 +1022,8 @@ func TestPluginStatusUpdateEncodingFailure(t *testing.T) { } func TestPluginStatusUpdateBufferSizeExceeded(t *testing.T) { + t.Parallel() + ctx := context.Background() testLogger := test.New() @@ -1111,6 +1138,8 @@ func TestPluginStatusUpdateBufferSizeExceeded(t *testing.T) { } func TestPluginStatusUpdateRateLimitExceeded(t *testing.T) { + t.Parallel() + ctx := context.Background() testLogger := test.New() @@ -1218,6 +1247,8 @@ func TestPluginStatusUpdateRateLimitExceeded(t *testing.T) { } func TestPluginRateLimitRequeue(t *testing.T) { + t.Parallel() + ctx := context.Background() numDecisions := 100 // 100 decisions per second @@ -1281,6 +1312,8 @@ func TestPluginRateLimitRequeue(t *testing.T) { } func TestPluginRateLimitDropCountStatus(t *testing.T) { + t.Parallel() + ctx := context.Background() testLogger := test.New() @@ -1381,6 +1414,8 @@ func TestPluginRateLimitDropCountStatus(t *testing.T) { } func TestChunkMaxUploadSizeLimitNDBCacheDropping(t *testing.T) { + t.Parallel() + ctx := context.Background() testLogger := test.New() @@ -1432,6 +1467,8 @@ func TestChunkMaxUploadSizeLimitNDBCacheDropping(t *testing.T) { } func TestPluginRateLimitBadConfig(t *testing.T) { + t.Parallel() + manager, _ := plugins.New(nil, "test-instance-id", inmem.New()) bufSize := 40000 @@ -1457,6 +1494,8 @@ func TestPluginRateLimitBadConfig(t *testing.T) { } func TestPluginNoLogging(t *testing.T) { + t.Parallel() + // Given no custom plugin, no service(s) and no console logging configured, // this should not be an error, but neither do we need to initiate the plugin cases := []struct { @@ -1491,6 +1530,8 @@ func TestPluginNoLogging(t *testing.T) { } func TestPluginTriggerManual(t *testing.T) { + t.Parallel() + ctx := context.Background() fixture := newTestFixture(t) @@ -1570,6 +1611,8 @@ func TestPluginTriggerManual(t *testing.T) { } func TestPluginTriggerManualWithTimeout(t *testing.T) { + t.Parallel() + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) defer cancel() @@ -1666,6 +1709,8 @@ func TestPluginTriggerManualWithTimeout(t *testing.T) { } func TestPluginGracefulShutdownFlushesDecisions(t *testing.T) { + t.Parallel() + ctx := context.Background() fixture := newTestFixture(t) @@ -1704,6 +1749,8 @@ func TestPluginGracefulShutdownFlushesDecisions(t *testing.T) { } func TestPluginTerminatesAfterGracefulShutdownPeriod(t *testing.T) { + t.Parallel() + ctx := context.Background() fixture := newTestFixture(t) @@ -1734,6 +1781,8 @@ func TestPluginTerminatesAfterGracefulShutdownPeriod(t *testing.T) { } func TestPluginTerminatesAfterGracefulShutdownPeriodWithoutLogs(t *testing.T) { + t.Parallel() + ctx := context.Background() fixture := newTestFixture(t) @@ -1753,6 +1802,7 @@ func TestPluginTerminatesAfterGracefulShutdownPeriodWithoutLogs(t *testing.T) { } func TestPluginReconfigure(t *testing.T) { + t.Parallel() ctx := context.Background() fixture := newTestFixture(t) @@ -1799,6 +1849,7 @@ func TestPluginReconfigure(t *testing.T) { } func TestPluginReconfigureUploadSizeLimit(t *testing.T) { + t.Parallel() ctx := context.Background() limit := int64(300) @@ -1854,6 +1905,8 @@ func (a appendingPrintHook) Print(_ print.Context, s string) error { } func TestPluginMasking(t *testing.T) { + t.Parallel() + tests := []struct { note string rawPolicy []byte @@ -2264,12 +2317,13 @@ func TestPluginMasking(t *testing.T) { } } - }) } } func TestPluginDrop(t *testing.T) { + t.Parallel() + // Test cases tests := []struct { note string @@ -2365,6 +2419,8 @@ func TestPluginDrop(t *testing.T) { } func TestPluginMaskErrorHandling(t *testing.T) { + t.Parallel() + rawPolicy := []byte(` package system.log import rego.v1 @@ -2439,6 +2495,8 @@ func TestPluginMaskErrorHandling(t *testing.T) { } func TestPluginDropErrorHandling(t *testing.T) { + t.Parallel() + rawPolicy := []byte(` package system.log import rego.v1 @@ -2649,6 +2707,8 @@ func newTestFixture(t *testing.T, opts ...testFixtureOptions) testFixture { } func TestParseConfigUseDefaultServiceNoConsole(t *testing.T) { + t.Parallel() + services := []string{ "s0", "s1", @@ -2671,6 +2731,8 @@ func TestParseConfigUseDefaultServiceNoConsole(t *testing.T) { } func TestParseConfigDefaultServiceWithConsole(t *testing.T) { + t.Parallel() + services := []string{ "s0", "s1", @@ -2693,6 +2755,8 @@ func TestParseConfigDefaultServiceWithConsole(t *testing.T) { } func TestParseConfigTriggerMode(t *testing.T) { + t.Parallel() + cases := []struct { note string config []byte @@ -2753,6 +2817,8 @@ func TestParseConfigTriggerMode(t *testing.T) { } func TestEventV1ToAST(t *testing.T) { + t.Parallel() + input := `{"foo": [{"bar": 1, "baz": {"2": 3.3333333, "4": null}}]}` var goInput interface{} = string(util.MustMarshalJSON(input)) astInput, err := roundtripJSONToAST(goInput) @@ -2952,12 +3018,12 @@ func TestEventV1ToAST(t *testing.T) { if expected.Compare(actual) != 0 { t.Fatalf("\nExpected:\n%s\n\nGot:\n%s\n\n", expected, actual) } - }) } } func TestPluginDefaultResourcePath(t *testing.T) { + t.Parallel() ctx := context.Background() @@ -2995,6 +3061,7 @@ func TestPluginDefaultResourcePath(t *testing.T) { } func TestPluginResourcePathAndPartitionName(t *testing.T) { + t.Parallel() ctx := context.Background() @@ -3036,6 +3103,7 @@ func TestPluginResourcePathAndPartitionName(t *testing.T) { } func TestPluginResourcePath(t *testing.T) { + t.Parallel() ctx := context.Background() diff --git a/plugins/rest/rest_test.go b/plugins/rest/rest_test.go index b526958335..4255262b1a 100644 --- a/plugins/rest/rest_test.go +++ b/plugins/rest/rest_test.go @@ -48,6 +48,8 @@ import ( const keyID = "key1" func TestAuthPluginWithNoAuthPluginLookup(t *testing.T) { + t.Parallel() + authPlugin := "anything" cfg := Config{ Credentials: struct { @@ -71,6 +73,8 @@ func TestAuthPluginWithNoAuthPluginLookup(t *testing.T) { } } +// Note(philipc): Cannot run this test in parallel, due to the t.Setenv calls +// from one of its helper methods. func TestNew(t *testing.T) { tests := []struct { name string @@ -871,6 +875,8 @@ func TestNew(t *testing.T) { } func TestNewWithResponseHeaderTimeout(t *testing.T) { + t.Parallel() + input := `{ "name": "foo", "url": "http://localhost", @@ -888,6 +894,8 @@ func TestNewWithResponseHeaderTimeout(t *testing.T) { } func TestDoWithResponseHeaderTimeout(t *testing.T) { + t.Parallel() + ctx := context.Background() tests := map[string]struct { @@ -949,6 +957,8 @@ func (*tracemock) NewHandler(http.Handler, string, tracing.Options) http.Handler } func TestDoWithDistributedTracingOpts(t *testing.T) { + t.Parallel() + ctx := context.Background() mock := tracemock{} tracing.RegisterHTTPTracing(&mock) @@ -986,6 +996,8 @@ func TestDoWithDistributedTracingOpts(t *testing.T) { } func TestDoWithResponseInClientLog(t *testing.T) { + t.Parallel() + ctx := context.Background() body := "Some Bad Request was received" @@ -1021,6 +1033,8 @@ func TestDoWithResponseInClientLog(t *testing.T) { } func TestDoWithTruncatedResponseInClientLog(t *testing.T) { + t.Parallel() + ctx := context.Background() ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { @@ -1056,6 +1070,8 @@ func TestDoWithTruncatedResponseInClientLog(t *testing.T) { } func TestValidUrl(t *testing.T) { + t.Parallel() + ts := testServer{ t: t, expMethod: "GET", @@ -1107,14 +1123,20 @@ func testBearerToken(t *testing.T, scheme, token string) { } func TestBearerTokenDefaultScheme(t *testing.T) { + t.Parallel() + testBearerToken(t, "", "secret") } func TestBearerTokenCustomScheme(t *testing.T) { + t.Parallel() + testBearerToken(t, "Acmecorp-Token", "secret") } func TestBearerTokenPath(t *testing.T) { + t.Parallel() + ts := testServer{ t: t, expBearerScheme: "", @@ -1177,6 +1199,8 @@ func TestBearerTokenPath(t *testing.T) { } func TestBearerWithCustomCACert(t *testing.T) { + t.Parallel() + ts := testServer{ t: t, tls: true, @@ -1206,6 +1230,8 @@ func TestBearerWithCustomCACert(t *testing.T) { } func TestBearerWithCustomCACertAndSystemCA(t *testing.T) { + t.Parallel() + ts := testServer{ t: t, tls: true, @@ -1236,6 +1262,8 @@ func TestBearerWithCustomCACertAndSystemCA(t *testing.T) { } func TestBearerTokenInvalidConfig(t *testing.T) { + t.Parallel() + ts := testServer{ t: t, expBearerScheme: "", @@ -1272,6 +1300,8 @@ func TestBearerTokenInvalidConfig(t *testing.T) { } func TestBearerTokenIsEncodedForOCI(t *testing.T) { + t.Parallel() + config := `{ "name": "foo", "type": "oci", @@ -1325,6 +1355,8 @@ func newTestBearerClient(t *testing.T, ts *testServer, tokenPath string) *Client } func TestClientCert(t *testing.T) { + t.Parallel() + ts := testServer{ t: t, tls: true, @@ -1383,6 +1415,8 @@ func TestClientCert(t *testing.T) { } func TestClientCertPassword(t *testing.T) { + t.Parallel() + ts := testServer{ t: t, tls: true, @@ -1411,6 +1445,8 @@ func TestClientCertPassword(t *testing.T) { } func TestClientTLSWithCustomCACert(t *testing.T) { + t.Parallel() + ts := testServer{ t: t, tls: true, @@ -1440,6 +1476,8 @@ func TestClientTLSWithCustomCACert(t *testing.T) { } func TestClientTLSWithCustomCACertAndSystemCA(t *testing.T) { + t.Parallel() + ts := testServer{ t: t, tls: true, @@ -1470,6 +1508,8 @@ func TestClientTLSWithCustomCACertAndSystemCA(t *testing.T) { } func TestOauth2ClientCredentials(t *testing.T) { + t.Parallel() + tests := []struct { ts *testServer ots *oauth2TestServer @@ -1540,6 +1580,8 @@ func TestOauth2ClientCredentials(t *testing.T) { } func TestOauth2ClientCredentialsExpiringTokenIsRefreshed(t *testing.T) { + t.Parallel() + ts := testServer{ t: t, expBearerToken: "token_1", @@ -1578,6 +1620,8 @@ func TestOauth2ClientCredentialsExpiringTokenIsRefreshed(t *testing.T) { } func TestOauth2ClientCredentialsNonExpiringTokenIsReused(t *testing.T) { + t.Parallel() + ts := testServer{ t: t, expBearerToken: "token_1", @@ -1606,6 +1650,8 @@ func TestOauth2ClientCredentialsNonExpiringTokenIsReused(t *testing.T) { } func TestOauth2JwtBearerGrantType(t *testing.T) { + t.Parallel() + key, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { t.Fatalf("Unexpected error %v", err) @@ -1645,6 +1691,8 @@ func TestOauth2JwtBearerGrantType(t *testing.T) { } func TestOauth2JwtBearerGrantTypePKCS8EncodedPrivateKey(t *testing.T) { + t.Parallel() + key, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { t.Fatalf("Unexpected error %v", err) @@ -1690,6 +1738,8 @@ func TestOauth2JwtBearerGrantTypePKCS8EncodedPrivateKey(t *testing.T) { } func TestOauth2JwtBearerGrantTypeEllipticCurveAlgorithm(t *testing.T) { + t.Parallel() + key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) if err != nil { t.Fatalf("Unexpected error %v", err) @@ -1740,6 +1790,8 @@ func TestOauth2JwtBearerGrantTypeEllipticCurveAlgorithm(t *testing.T) { } func TestOauth2ClientCredentialsJwtAuthentication(t *testing.T) { + t.Parallel() + key, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { t.Fatalf("Unexpected error %v", err) @@ -1786,6 +1838,8 @@ func TestOauth2ClientCredentialsJwtAuthentication(t *testing.T) { // https://github.com/open-policy-agent/opa/issues/3255 func TestS3SigningInstantiationInitializesLogger(t *testing.T) { + t.Parallel() + config := `{ "name": "foo", "url": "https://bundles.example.com", @@ -1817,6 +1871,8 @@ func TestS3SigningInstantiationInitializesLogger(t *testing.T) { } func TestS3SigningMultiCredentialProvider(t *testing.T) { + t.Parallel() + credentialProviderCount := 4 config := `{ "name": "foo", @@ -1866,6 +1922,8 @@ func TestS3SigningMultiCredentialProvider(t *testing.T) { } func TestAWSCredentialServiceChain(t *testing.T) { + t.Parallel() + tests := []struct { name string input string @@ -1962,6 +2020,8 @@ func TestAWSCredentialServiceChain(t *testing.T) { } func TestDebugLoggingRequestMaskAuthorizationHeader(t *testing.T) { + t.Parallel() + token := "secret" plaintext := "plaintext" ts := testServer{t: t, expBearerToken: token} @@ -2509,6 +2569,8 @@ func (*myPluginMock) Prepare(*http.Request) error { return nil } +// Note(philipc): Cannot run this test in parallel, due to the t.Setenv calls +// from one of its helper methods. func TestOauth2ClientCredentialsGrantTypeWithKms(t *testing.T) { // DER-encoded object from KMS as explained here: https://docs.aws.amazon.com/kms/latest/APIReference/API_Sign.html#API_Sign_ResponseSyntax diff --git a/server/server_test.go b/server/server_test.go index 8e80f77117..be8e515a82 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -70,18 +70,23 @@ type tr struct { } func TestUnversionedGetHealth(t *testing.T) { + t.Parallel() + f := newFixture(t) req := newReqUnversioned(http.MethodGet, "/health", "") validateDiagnosticRequest(t, f, req, 200, `{}`) } func TestUnversionedGetHealthBundleNoBundleSet(t *testing.T) { + t.Parallel() + f := newFixture(t) req := newReqUnversioned(http.MethodGet, "/health?bundles=true", "") validateDiagnosticRequest(t, f, req, 200, `{}`) } func TestUnversionedGetHealthCheckOnlyBundlePlugin(t *testing.T) { + t.Parallel() f := newFixture(t) @@ -102,6 +107,7 @@ func TestUnversionedGetHealthCheckOnlyBundlePlugin(t *testing.T) { } func TestUnversionedGetHealthCheckDiscoveryWithBundle(t *testing.T) { + t.Parallel() f := newFixture(t) @@ -129,6 +135,7 @@ func TestUnversionedGetHealthCheckDiscoveryWithBundle(t *testing.T) { } func TestUnversionedGetHealthCheckBundleActivationSingleLegacy(t *testing.T) { + t.Parallel() // Initialize the server as if there is no bundle plugin @@ -156,6 +163,7 @@ func TestUnversionedGetHealthCheckBundleActivationSingleLegacy(t *testing.T) { } func TestBundlesReady(t *testing.T) { + t.Parallel() cases := []struct { note string @@ -247,6 +255,7 @@ func TestBundlesReady(t *testing.T) { } func TestUnversionedGetHealthCheckDiscoveryWithPlugins(t *testing.T) { + t.Parallel() // Use the same server through the cases, the status updates apply incrementally to it. f := newFixture(t) @@ -387,6 +396,7 @@ func TestUnversionedGetHealthCheckDiscoveryWithPlugins(t *testing.T) { } func TestUnversionedGetHealthCheckDiscoveryWithPluginsAndExclude(t *testing.T) { + t.Parallel() // Use the same server through the cases, the status updates apply incrementally to it. f := newFixture(t) @@ -499,6 +509,7 @@ func TestUnversionedGetHealthCheckDiscoveryWithPluginsAndExclude(t *testing.T) { } func TestUnversionedGetHealthCheckBundleAndPlugins(t *testing.T) { + t.Parallel() cases := []struct { note string @@ -588,12 +599,16 @@ func TestUnversionedGetHealthCheckBundleAndPlugins(t *testing.T) { } func TestUnversionedGetHealthWithPolicyMissing(t *testing.T) { + t.Parallel() + f := newFixture(t) req := newReqUnversioned(http.MethodGet, "/health/live", "") validateDiagnosticRequest(t, f, req, 500, `{"error":"health check (data.system.health.live) was undefined"}`) } func TestUnversionedGetHealthWithPolicyUpdates(t *testing.T) { + t.Parallel() + ctx := context.Background() store := inmem.New() txn := storage.NewTransactionOrDie(ctx, store, storage.WriteParams) @@ -634,6 +649,8 @@ func TestUnversionedGetHealthWithPolicyUpdates(t *testing.T) { } func TestUnversionedGetHealthWithPolicyUsingPlugins(t *testing.T) { + t.Parallel() + ctx := context.Background() store := inmem.New() txn := storage.NewTransactionOrDie(ctx, store, storage.WriteParams) @@ -696,6 +713,8 @@ func TestUnversionedGetHealthWithPolicyUsingPlugins(t *testing.T) { } func TestDataV0(t *testing.T) { + t.Parallel() + testMod1 := `package test import rego.v1 @@ -757,6 +776,8 @@ func TestDataV0(t *testing.T) { // Tests that the responses for (theoretically) valid resources but with forbidden methods return the proper status code func Test405StatusCodev1(t *testing.T) { + t.Parallel() + tests := []struct { note string reqs []tr @@ -820,6 +841,8 @@ func Test405StatusCodev1(t *testing.T) { // Tests that the responses for (theoretically) valid resources but with forbidden methods return the proper status code func Test405StatusCodev0(t *testing.T) { + t.Parallel() + tests := []struct { note string reqs []tr @@ -853,6 +876,7 @@ func Test405StatusCodev0(t *testing.T) { } func TestCompileV1(t *testing.T) { + t.Parallel() mod := `package test import rego.v1 @@ -1016,6 +1040,8 @@ func TestCompileV1(t *testing.T) { } func TestCompileV1Observability(t *testing.T) { + t.Parallel() + ctx, cancel := context.WithCancel(context.Background()) defer cancel() test.WithTempFS(nil, func(root string) { @@ -1062,6 +1088,8 @@ func TestCompileV1Observability(t *testing.T) { } func TestCompileV1UnsafeBuiltin(t *testing.T) { + t.Parallel() + f := newFixture(t) query := `{"query": "http.send({\"method\": \"get\", \"url\": \"foo.com\"}, x)"}` @@ -1087,6 +1115,8 @@ func TestCompileV1UnsafeBuiltin(t *testing.T) { } func TestDataV1Redirection(t *testing.T) { + t.Parallel() + f := newFixture(t) // Testing redirect at the root level if err := f.v1(http.MethodPut, "/data/", `{"foo": [1,2,3]}`, 301, ""); err != nil { @@ -1121,6 +1151,8 @@ func TestDataV1Redirection(t *testing.T) { } func TestDataV1(t *testing.T) { + t.Parallel() + testMod1 := `package testmod import rego.v1 @@ -1531,6 +1563,8 @@ p = true if { false }` } func TestDataV1Metrics(t *testing.T) { + t.Parallel() + ctx, cancel := context.WithCancel(context.Background()) defer cancel() test.WithTempFS(nil, func(root string) { @@ -1569,6 +1603,8 @@ func TestDataV1Metrics(t *testing.T) { } func TestConfigV1(t *testing.T) { + t.Parallel() + f := newFixture(t) c := []byte(`{"services": { @@ -1633,6 +1669,7 @@ func TestConfigV1(t *testing.T) { } func TestDataYAML(t *testing.T) { + t.Parallel() testMod1 := `package testmod import rego.v1 @@ -1685,6 +1722,8 @@ main = data.testmod.gt1`, 200, ""); err != nil { } func TestDataPutV1IfNoneMatch(t *testing.T) { + t.Parallel() + f := newFixture(t) if err := f.v1(http.MethodPut, "/data/a/b/c", "0", 204, ""); err != nil { t.Fatalf("Unexpected error from PUT /data/a/b/c: %v", err) @@ -1734,6 +1773,8 @@ func generateJSONBenchmarkData(k, v int) map[string]interface{} { // Ref: https://github.com/open-policy-agent/opa/issues/6804 func TestDataGetV1CompressedRequestWithAuthorizer(t *testing.T) { + t.Parallel() + tests := []struct { note string payload []byte @@ -1840,6 +1881,8 @@ allow if { // Tests to ensure the body size limits work, for compressed requests. func TestDataPostV1CompressedDecodingLimits(t *testing.T) { + t.Parallel() + defaultMaxLen := int64(1024) defaultGzipMaxLen := int64(1024) @@ -2035,6 +2078,8 @@ allow if { } func TestDataPostV0CompressedResponse(t *testing.T) { + t.Parallel() + tests := []struct { gzipMinLength int compressedResponse bool @@ -2101,6 +2146,8 @@ allow_request if { flag == true } } func TestDataPostV1CompressedResponse(t *testing.T) { + t.Parallel() + tests := []struct { gzipMinLength int compressedResponse bool @@ -2174,6 +2221,8 @@ hello if { } func TestCompileV1CompressedResponse(t *testing.T) { + t.Parallel() + tests := []struct { gzipMinLength int compressedResponse bool @@ -2263,6 +2312,8 @@ func TestCompileV1CompressedResponse(t *testing.T) { } func TestDataPostV0CompressedRequest(t *testing.T) { + t.Parallel() + f := newFixture(t) // create the policy err := f.v1(http.MethodPut, "/policies/test", `package opa.examples @@ -2289,6 +2340,8 @@ allow_request if { flag == true } } func TestDataPostV1CompressedRequest(t *testing.T) { + t.Parallel() + f := newFixture(t) // create the policy err := f.v1(http.MethodPut, "/policies/test", `package test @@ -2326,6 +2379,8 @@ hello if { } func TestCompileV1CompressedRequest(t *testing.T) { + t.Parallel() + f := newFixture(t) // create the policy mod := `package test @@ -2378,6 +2433,7 @@ func TestCompileV1CompressedRequest(t *testing.T) { } func TestBundleScope(t *testing.T) { + t.Parallel() ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -2503,6 +2559,7 @@ func TestBundleScope(t *testing.T) { } func TestBundleScopeMultiBundle(t *testing.T) { + t.Parallel() ctx := context.Background() @@ -2568,6 +2625,8 @@ func TestBundleScopeMultiBundle(t *testing.T) { } func TestBundleNoRoots(t *testing.T) { + t.Parallel() + ctx := context.Background() f := newFixture(t) @@ -2705,6 +2764,8 @@ func TestDataUpdate(t *testing.T) { } func TestDataGetExplainFull(t *testing.T) { + t.Parallel() + f := newFixture(t) err := f.v1(http.MethodPut, "/data/x", `{"a":1,"b":2}`, 204, "") @@ -2794,6 +2855,7 @@ func TestDataGetExplainFull(t *testing.T) { } func TestDataPostWithActiveStoreWriteTxn(t *testing.T) { + t.Parallel() f := newFixture(t) @@ -2832,6 +2894,8 @@ p = [1, 2, 3, 4] if { true }`, 200, "") } func TestDataPostExplain(t *testing.T) { + t.Parallel() + f := newFixture(t) err := f.v1(http.MethodPut, "/policies/test", `package test @@ -2872,6 +2936,8 @@ p = [1, 2, 3, 4] if { true }`, 200, "") } func TestDataPostExplainNotes(t *testing.T) { + t.Parallel() + f := newFixture(t) err := f.v1(http.MethodPut, "/policies/test", ` @@ -2917,6 +2983,7 @@ func TestDataPostExplainNotes(t *testing.T) { } func TestDataProvenanceSingleBundle(t *testing.T) { + t.Parallel() f := newFixture(t) @@ -2987,6 +3054,7 @@ func TestDataProvenanceSingleBundle(t *testing.T) { } func TestDataProvenanceSingleFileBundle(t *testing.T) { + t.Parallel() f := newFixture(t) @@ -3035,6 +3103,7 @@ func TestDataProvenanceSingleFileBundle(t *testing.T) { } func TestDataProvenanceMultiBundle(t *testing.T) { + t.Parallel() f := newFixture(t) @@ -3145,6 +3214,8 @@ func TestDataProvenanceMultiBundle(t *testing.T) { } func TestDataMetricsEval(t *testing.T) { + t.Parallel() + // These tests all use the POST /v1/data API with ?metrics appended. // We're setting up the disk store because that injects a few extra metrics, // which storage/inmem does not. @@ -3222,6 +3293,7 @@ func assertMetricsExist(t *testing.T, metrics types.MetricsV1, expected []string } func TestV1Pretty(t *testing.T) { + t.Parallel() f := newFixture(t) err := f.v1(http.MethodPatch, "/data/x", `[{"op": "add", "path":"/", "value": [1,2,3,4]}]`, 204, "") @@ -3249,6 +3321,8 @@ func TestV1Pretty(t *testing.T) { } func TestPoliciesPutV1(t *testing.T) { + t.Parallel() + f := newFixture(t) req := newReqV1(http.MethodPut, "/policies/1", testMod) @@ -3269,6 +3343,8 @@ func TestPoliciesPutV1(t *testing.T) { } func TestPoliciesPutV1Empty(t *testing.T) { + t.Parallel() + f := newFixture(t) req := newReqV1(http.MethodPut, "/policies/1", "") @@ -3280,6 +3356,8 @@ func TestPoliciesPutV1Empty(t *testing.T) { } func TestPoliciesPutV1ParseError(t *testing.T) { + t.Parallel() + f := newFixture(t) req := newReqV1(http.MethodPut, "/policies/test", ` package a.b.c @@ -3334,6 +3412,8 @@ func TestPoliciesPutV1ParseError(t *testing.T) { } func TestPoliciesPutV1CompileError(t *testing.T) { + t.Parallel() + f := newFixture(t) req := newReqV1(http.MethodPut, "/policies/test", `package a.b.c @@ -3370,6 +3450,8 @@ q[x] { p[x] }`, } func TestPoliciesPutV1Noop(t *testing.T) { + t.Parallel() + f := newFixture(t) err := f.v1("PUT", "/policies/test?metrics", `package foo`, 200, "") if err != nil { @@ -3422,6 +3504,8 @@ func TestPoliciesPutV1Noop(t *testing.T) { } func TestPoliciesListV1(t *testing.T) { + t.Parallel() + f := newFixture(t) putPolicy(t, f, testMod) @@ -3473,6 +3557,8 @@ func assertListPolicy(t *testing.T, f *fixture, expected []types.PolicyV1) { } func TestPoliciesGetV1(t *testing.T) { + t.Parallel() + f := newFixture(t) put := newReqV1(http.MethodPut, "/policies/1", testMod) f.server.Handler.ServeHTTP(f.recorder, put) @@ -3503,6 +3589,8 @@ func TestPoliciesGetV1(t *testing.T) { } func TestPoliciesDeleteV1(t *testing.T) { + t.Parallel() + f := newFixture(t) put := newReqV1(http.MethodPut, "/policies/1", testMod) f.server.Handler.ServeHTTP(f.recorder, put) @@ -3538,6 +3626,8 @@ func TestPoliciesDeleteV1(t *testing.T) { } func TestPoliciesPathSlashes(t *testing.T) { + t.Parallel() + f := newFixture(t) if err := f.v1(http.MethodPut, "/policies/a/b/c.rego", testMod, 200, ""); err != nil { t.Fatalf("Unexpected error: %v", err) @@ -3548,6 +3638,8 @@ func TestPoliciesPathSlashes(t *testing.T) { } func TestPoliciesUrlEncoded(t *testing.T) { + t.Parallel() + const expectedPolicyID = "/a policy/another-component" var urlEscapedPolicyID = url.PathEscape(expectedPolicyID) f := newFixture(t) @@ -3590,6 +3682,7 @@ func TestPoliciesUrlEncoded(t *testing.T) { } func TestStatusV1(t *testing.T) { + t.Parallel() f := newFixture(t) @@ -3680,6 +3773,7 @@ func TestStatusV1(t *testing.T) { } func TestStatusV1MetricsWithSystemAuthzPolicy(t *testing.T) { + t.Parallel() ctx := context.Background() @@ -3849,6 +3943,8 @@ func TestStatusV1MetricsWithSystemAuthzPolicy(t *testing.T) { } func TestQueryPostBasic(t *testing.T) { + t.Parallel() + f := newFixture(t) f.server, _ = New(). WithAddresses([]string{"localhost:8182"}). @@ -3873,6 +3969,7 @@ func TestQueryPostBasic(t *testing.T) { } func TestDecisionIDs(t *testing.T) { + t.Parallel() f := newFixture(t) @@ -3924,6 +4021,8 @@ func TestDecisionIDs(t *testing.T) { } func TestDecisionLoggingWithHTTPRequestContext(t *testing.T) { + t.Parallel() + f := newFixture(t) decisions := []*Info{} @@ -3968,6 +4067,8 @@ func TestDecisionLoggingWithHTTPRequestContext(t *testing.T) { } func TestDecisionLogging(t *testing.T) { + t.Parallel() + f := newFixture(t) decisions := []*Info{} @@ -4158,6 +4259,7 @@ func TestDecisionLogging(t *testing.T) { } func TestDecisionLogErrorMessage(t *testing.T) { + t.Parallel() f := newFixture(t) @@ -4174,6 +4276,8 @@ func TestDecisionLogErrorMessage(t *testing.T) { } func TestQueryV1(t *testing.T) { + t.Parallel() + ctx, cancel := context.WithCancel(context.Background()) defer cancel() test.WithTempFS(nil, func(root string) { @@ -4221,6 +4325,8 @@ func TestQueryV1(t *testing.T) { } func TestBadQueryV1(t *testing.T) { + t.Parallel() + f := newFixture(t) expectedErr := `{ @@ -4250,6 +4356,8 @@ func TestBadQueryV1(t *testing.T) { } func TestQueryV1UnsafeBuiltin(t *testing.T) { + t.Parallel() + f := newFixture(t) query := `/query?q=http.send({"method": "get", "url": "foo.com"}, x)` @@ -4276,6 +4384,7 @@ func TestQueryV1UnsafeBuiltin(t *testing.T) { } func TestUnversionedPost(t *testing.T) { + t.Parallel() f := newFixture(t) @@ -4398,6 +4507,8 @@ func TestUnversionedPost(t *testing.T) { } func TestQueryV1Explain(t *testing.T) { + t.Parallel() + f := newFixture(t) get := newReqV1(http.MethodGet, `/query?q=a=[1,2,3]%3Ba[i]=x&explain=debug`, "") f.server.Handler.ServeHTTP(f.recorder, get) @@ -4420,6 +4531,7 @@ func TestQueryV1Explain(t *testing.T) { } func TestAuthorization(t *testing.T) { + t.Parallel() ctx := context.Background() store := inmem.New() @@ -4541,6 +4653,7 @@ func TestAuthorization(t *testing.T) { } func TestAuthorizationUsesInterQueryCache(t *testing.T) { + t.Parallel() ctx := context.Background() store := inmem.New() @@ -4629,6 +4742,7 @@ func validateAuthorizedRequest(t *testing.T, s *Server, req *http.Request, exp i } func TestServerUsesAuthorizerParsedBody(t *testing.T) { + t.Parallel() // Construct a request w/ a different message body (this should never happen.) req, err := http.NewRequest(http.MethodPost, "http://localhost:8182/v1/data/test/echo", bytes.NewBufferString(`{"foo": "bad"}`)) @@ -4679,6 +4793,8 @@ func TestServerUsesAuthorizerParsedBody(t *testing.T) { } func TestServerReloadTrigger(t *testing.T) { + t.Parallel() + f := newFixture(t) store := f.server.store ctx := context.Background() @@ -4699,6 +4815,8 @@ func TestServerReloadTrigger(t *testing.T) { } func TestServerClearsCompilerConflictCheck(t *testing.T) { + t.Parallel() + f := newFixture(t) store := f.server.store ctx := context.Background() @@ -4777,6 +4895,7 @@ func (queryBindingErrStore) Unregister(context.Context, storage.Transaction, str } func TestQueryBindingIterationError(t *testing.T) { + t.Parallel() ctx := context.Background() mock := &queryBindingErrStore{} @@ -5091,6 +5210,8 @@ func mustUnmarshalTrace(t types.TraceV1) (trace types.TraceV1Raw) { } func TestShutdown(t *testing.T) { + t.Parallel() + f := newFixture(t, func(s *Server) { s.WithDiagnosticAddresses([]string{":8443"}) }) @@ -5115,6 +5236,8 @@ func TestShutdown(t *testing.T) { } func TestShutdownError(t *testing.T) { + t.Parallel() + f := newFixture(t, func(s *Server) { s.WithDiagnosticAddresses([]string{":8443"}) }) @@ -5140,6 +5263,8 @@ func TestShutdownError(t *testing.T) { } func TestShutdownMultipleErrors(t *testing.T) { + t.Parallel() + f := newFixture(t, func(s *Server) { s.WithDiagnosticAddresses([]string{":8443"}) }) @@ -5173,6 +5298,8 @@ func TestShutdownMultipleErrors(t *testing.T) { } func TestAddrsNoListeners(t *testing.T) { + t.Parallel() + s := New() a := s.Addrs() if len(a) != 0 { @@ -5181,6 +5308,8 @@ func TestAddrsNoListeners(t *testing.T) { } func TestAddrsWithEmptyListenAddr(t *testing.T) { + t.Parallel() + s := New() s.httpListeners = []httpListener{&mockHTTPListener{}} a := s.Addrs() @@ -5190,6 +5319,8 @@ func TestAddrsWithEmptyListenAddr(t *testing.T) { } func TestAddrsWithListenAddr(t *testing.T) { + t.Parallel() + s := New() s.httpListeners = []httpListener{&mockHTTPListener{addrs: ":8181"}} a := s.Addrs() @@ -5199,6 +5330,8 @@ func TestAddrsWithListenAddr(t *testing.T) { } func TestAddrsWithMixedListenerAddr(t *testing.T) { + t.Parallel() + s := New() addrs := []string{":8181", "", "unix:///var/tmp/foo.sock"} expected := []string{":8181", "unix:///var/tmp/foo.sock"} @@ -5228,6 +5361,8 @@ func TestAddrsWithMixedListenerAddr(t *testing.T) { } func TestDiagnosticAddrsNoListeners(t *testing.T) { + t.Parallel() + s := New() a := s.DiagnosticAddrs() if len(a) != 0 { @@ -5236,6 +5371,8 @@ func TestDiagnosticAddrsNoListeners(t *testing.T) { } func TestDiagnosticAddrsWithEmptyListenAddr(t *testing.T) { + t.Parallel() + s := New() s.httpListeners = []httpListener{&mockHTTPListener{t: diagnosticListenerType}} a := s.DiagnosticAddrs() @@ -5245,6 +5382,8 @@ func TestDiagnosticAddrsWithEmptyListenAddr(t *testing.T) { } func TestDiagnosticAddrsWithListenAddr(t *testing.T) { + t.Parallel() + s := New() s.httpListeners = []httpListener{&mockHTTPListener{addrs: ":8181", t: diagnosticListenerType}} a := s.DiagnosticAddrs() @@ -5254,6 +5393,8 @@ func TestDiagnosticAddrsWithListenAddr(t *testing.T) { } func TestDiagnosticAddrsWithMixedListenerAddr(t *testing.T) { + t.Parallel() + s := New() addrs := []string{":8181", "", "unix:///var/tmp/foo.sock"} expected := []string{":8181", "unix:///var/tmp/foo.sock"} @@ -5283,6 +5424,8 @@ func TestDiagnosticAddrsWithMixedListenerAddr(t *testing.T) { } func TestMixedAddrTypes(t *testing.T) { + t.Parallel() + s := New() s.httpListeners = []httpListener{} @@ -5321,6 +5464,8 @@ func TestMixedAddrTypes(t *testing.T) { } func TestCustomRoute(t *testing.T) { + t.Parallel() + router := mux.NewRouter() router.HandleFunc("/customEndpoint", func(w http.ResponseWriter, _ *http.Request) { _, _ = w.Write([]byte(`{"myCustomResponse": true}`)) // ignore error @@ -5342,6 +5487,8 @@ func TestCustomRoute(t *testing.T) { } func TestDiagnosticRoutes(t *testing.T) { + t.Parallel() + cases := []struct { path string should404 bool @@ -5386,6 +5533,8 @@ func TestDiagnosticRoutes(t *testing.T) { } func TestDistributedTracingEnabled(t *testing.T) { + t.Parallel() + c := []byte(`{"distributed_tracing": { "type": "grpc" }}`) @@ -5398,6 +5547,8 @@ func TestDistributedTracingEnabled(t *testing.T) { } func TestDistributedTracingResourceAttributes(t *testing.T) { + t.Parallel() + c := []byte(`{"distributed_tracing": { "type": "grpc", "service_name": "my-service", @@ -5425,6 +5576,7 @@ func TestDistributedTracingResourceAttributes(t *testing.T) { } func TestCertPoolReloading(t *testing.T) { + t.Parallel() ctx := context.Background() @@ -5836,6 +5988,7 @@ func TestCertPoolReloading(t *testing.T) { } func TestCertReloading(t *testing.T) { + t.Parallel() ctx := context.Background() diff --git a/topdown/cache/cache_test.go b/topdown/cache/cache_test.go index b5c1a3865a..fe86bd9581 100644 --- a/topdown/cache/cache_test.go +++ b/topdown/cache/cache_test.go @@ -15,6 +15,8 @@ import ( ) func TestParseCachingConfig(t *testing.T) { + t.Parallel() + maxSize := new(int64) *maxSize = defaultMaxSizeBytes period := new(int64) @@ -90,6 +92,7 @@ func TestParseCachingConfig(t *testing.T) { } func TestInsert(t *testing.T) { + t.Parallel() in := `{"inter_query_builtin_cache": {"max_size_bytes": 20},}` // 20 byte limit for test purposes @@ -178,6 +181,7 @@ func TestInsert(t *testing.T) { } func TestInterQueryValueCache(t *testing.T) { + t.Parallel() in := `{"inter_query_builtin_value_cache": {"max_num_entries": 4},}` @@ -269,6 +273,8 @@ func TestInterQueryValueCache(t *testing.T) { } func TestConcurrentInsert(t *testing.T) { + t.Parallel() + in := `{"inter_query_builtin_cache": {"max_size_bytes": 20},}` // 20 byte limit for test purposes config, err := ParseCachingConfig([]byte(in)) @@ -321,6 +327,8 @@ func TestConcurrentInsert(t *testing.T) { } func TestClone(t *testing.T) { + t.Parallel() + in := `{"inter_query_builtin_cache": {"max_size_bytes": 40},}` config, err := ParseCachingConfig([]byte(in)) @@ -362,6 +370,8 @@ func TestClone(t *testing.T) { } func TestDelete(t *testing.T) { + t.Parallel() + config, err := ParseCachingConfig(nil) if err != nil { t.Fatalf("Unexpected error %v", err) @@ -387,6 +397,8 @@ func TestDelete(t *testing.T) { } func TestInsertWithExpiryAndEviction(t *testing.T) { + t.Parallel() + // 50 byte max size // 1s stale cleanup period // 80% threshold to for FIFO eviction (eviction after 40 bytes) @@ -431,6 +443,8 @@ func TestInsertWithExpiryAndEviction(t *testing.T) { } func TestInsertHighTTLWithStaleEntryCleanup(t *testing.T) { + t.Parallel() + // 40 byte max size // 1s stale cleanup period // 100% threshold to for FIFO eviction (eviction after 40 bytes) @@ -472,6 +486,8 @@ func TestInsertHighTTLWithStaleEntryCleanup(t *testing.T) { } func TestInsertHighTTLWithoutStaleEntryCleanup(t *testing.T) { + t.Parallel() + // 40 byte max size // 0s stale cleanup period -> no cleanup // 100% threshold to for FIFO eviction (eviction after 40 bytes) @@ -510,6 +526,8 @@ func TestInsertHighTTLWithoutStaleEntryCleanup(t *testing.T) { } func TestZeroExpiryTime(t *testing.T) { + t.Parallel() + // 20 byte max size // 1s stale cleanup period // 100% threshold to for FIFO eviction (eviction after 40 bytes) @@ -536,6 +554,8 @@ func TestZeroExpiryTime(t *testing.T) { } func TestCancelNewInterQueryCacheWithContext(t *testing.T) { + t.Parallel() + // 40 byte max size // 1s stale cleanup period // 100% threshold to for FIFO eviction (eviction after 40 bytes) @@ -565,6 +585,8 @@ func TestCancelNewInterQueryCacheWithContext(t *testing.T) { } func TestUpdateConfig(t *testing.T) { + t.Parallel() + config, err := ParseCachingConfig(nil) if err != nil { t.Fatalf("Unexpected error %v", err) @@ -592,6 +614,8 @@ func TestUpdateConfig(t *testing.T) { } func TestDefaultConfigValues(t *testing.T) { + t.Parallel() + c := NewInterQueryCache(nil) actualC, ok := c.(*cache) if !ok {