From 9329b09d4376ebeaf5550d9a9506ba7114499677 Mon Sep 17 00:00:00 2001 From: Keenan Nemetz Date: Thu, 4 Apr 2024 15:19:24 -0700 Subject: [PATCH 1/2] add test flag to skip network tests --- tests/integration/test_case.go | 32 ++++++++++++++++++++++++++++++++ tests/integration/utils2.go | 25 ++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_case.go b/tests/integration/test_case.go index 8d9315e4fa..cc5cca24a5 100644 --- a/tests/integration/test_case.go +++ b/tests/integration/test_case.go @@ -593,3 +593,35 @@ type BackupImport struct { // contains this string. ExpectedError string } + +// IsNetworkAction returns true if the given action involves the network subsystem. +func IsNetworkAction(act any) bool { + switch act.(type) { + case ConfigureNode: + return true + + case ConnectPeers: + return true + + case ConfigureReplicator: + return true + + case DeleteReplicator: + return true + + case SubscribeToCollection: + return true + + case UnsubscribeToCollection: + return true + + case GetAllP2PCollections: + return true + + case WaitForSync: + return true + + default: + return false + } +} diff --git a/tests/integration/utils2.go b/tests/integration/utils2.go index fe79b18106..05dd77b01d 100644 --- a/tests/integration/utils2.go +++ b/tests/integration/utils2.go @@ -15,6 +15,7 @@ import ( "fmt" "os" "reflect" + "strconv" "strings" "testing" "time" @@ -40,7 +41,10 @@ import ( "github.com/sourcenetwork/defradb/tests/predefined" ) -const mutationTypeEnvName = "DEFRA_MUTATION_TYPE" +const ( + mutationTypeEnvName = "DEFRA_MUTATION_TYPE" + skipNetworkTestsEnvName = "DEFRA_SKIP_NETWORK_TESTS" +) // The MutationType that tests will run using. // @@ -72,6 +76,8 @@ const ( var ( log = corelog.NewLogger("tests.integration") mutationType MutationType + // skipNetworkTests will skip any tests that involve network actions + skipNetworkTests = false ) const ( @@ -95,6 +101,9 @@ func init() { // mutation type. mutationType = CollectionSaveMutationType } + if value, ok := os.LookupEnv(skipNetworkTestsEnvName); ok { + skipNetworkTests, _ = strconv.ParseBool(value) + } } // AssertPanic asserts that the code inside the specified PanicTestFunc panics. @@ -131,6 +140,7 @@ func ExecuteTestCase( collectionNames := getCollectionNames(testCase) changeDetector.PreTestChecks(t, collectionNames) skipIfMutationTypeUnsupported(t, testCase.SupportedMutationTypes) + skipIfNetworkTest(t, testCase.Actions) var clients []ClientType if httpClient { @@ -182,6 +192,7 @@ func executeTestCase( corelog.Any("client", clientType), corelog.Any("mutationType", mutationType), corelog.String("databaseDir", databaseDir), + corelog.Bool("skipNetworkTests", skipNetworkTests), corelog.Bool("changeDetector.Enabled", changeDetector.Enabled), corelog.Bool("changeDetector.SetupOnly", changeDetector.SetupOnly), corelog.String("changeDetector.SourceBranch", changeDetector.SourceBranch), @@ -2001,6 +2012,18 @@ func skipIfMutationTypeUnsupported(t *testing.T, supportedMutationTypes immutabl } } +// skipIfNetworkTest skips the current test if the given actions +// contain network actions and skipNetworkTests is true. +func skipIfNetworkTest(t *testing.T, actions []any) { + hasNetworkAction := false + for _, act := range actions { + hasNetworkAction = hasNetworkAction || IsNetworkAction(act) + } + if skipNetworkTests && hasNetworkAction { + t.Skip("test involves network actions") + } +} + func ParseSDL(gqlSDL string) (map[string]client.CollectionDefinition, error) { parser, err := graphql.NewParser() if err != nil { From a90cdbfc776f6a5e868963288b06a9d4d4a43f17 Mon Sep 17 00:00:00 2001 From: Keenan Nemetz Date: Fri, 5 Apr 2024 09:33:14 -0700 Subject: [PATCH 2/2] simplify IsNetworkAction --- tests/integration/test_case.go | 32 -------------------------------- tests/integration/utils2.go | 5 ++++- 2 files changed, 4 insertions(+), 33 deletions(-) diff --git a/tests/integration/test_case.go b/tests/integration/test_case.go index cc5cca24a5..8d9315e4fa 100644 --- a/tests/integration/test_case.go +++ b/tests/integration/test_case.go @@ -593,35 +593,3 @@ type BackupImport struct { // contains this string. ExpectedError string } - -// IsNetworkAction returns true if the given action involves the network subsystem. -func IsNetworkAction(act any) bool { - switch act.(type) { - case ConfigureNode: - return true - - case ConnectPeers: - return true - - case ConfigureReplicator: - return true - - case DeleteReplicator: - return true - - case SubscribeToCollection: - return true - - case UnsubscribeToCollection: - return true - - case GetAllP2PCollections: - return true - - case WaitForSync: - return true - - default: - return false - } -} diff --git a/tests/integration/utils2.go b/tests/integration/utils2.go index 05dd77b01d..18c97e76d1 100644 --- a/tests/integration/utils2.go +++ b/tests/integration/utils2.go @@ -2017,7 +2017,10 @@ func skipIfMutationTypeUnsupported(t *testing.T, supportedMutationTypes immutabl func skipIfNetworkTest(t *testing.T, actions []any) { hasNetworkAction := false for _, act := range actions { - hasNetworkAction = hasNetworkAction || IsNetworkAction(act) + switch act.(type) { + case ConfigureNode: + hasNetworkAction = true + } } if skipNetworkTests && hasNetworkAction { t.Skip("test involves network actions")