Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add flag to skip network tests #2495

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions tests/integration/test_case.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: I don't think you need to check all of these? ConfigureNode is required for all P2P tests IIRC. Expecting all future network test actions to consistently be added to this switch seems a little optimistic to me and I would rather avoid the need if we can.

suggestion: If keeping all the actions in the switch, I think collapsing them into a single case might be easier to read:

switch act.(type) {
	case ConfigureNode,
	        ConnectPeers,
	        ConfigureReplicator,
	        etc...:
	      return true
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified it to just check for 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
}
}
25 changes: 24 additions & 1 deletion tests/integration/utils2.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"fmt"
"os"
"reflect"
"strconv"
"strings"
"testing"
"time"
Expand All @@ -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.
//
Expand Down Expand Up @@ -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 (
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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 {
Expand Down
Loading