Skip to content

Commit

Permalink
test: Add flag to skip network tests (#2495)
Browse files Browse the repository at this point in the history
## Relevant issue(s)

Resolves #2494 

## Description

This PR adds a test flag set via an environment variable to skip any
tests that involve network actions.

## Tasks

- [x] I made sure the code is well commented, particularly
hard-to-understand areas.
- [x] I made sure the repository-held documentation is changed
accordingly.
- [x] I made sure the pull request title adheres to the conventional
commit style (the subset used in the project can be found in
[tools/configs/chglog/config.yml](tools/configs/chglog/config.yml)).
- [x] I made sure to discuss its limitations such as threats to
validity, vulnerability to mistake and misuse, robustness to
invalidation of assumptions, resource requirements, ...

## How has this been tested?

`make test`

Specify the platform(s) on which this was tested:
- MacOS
  • Loading branch information
nasdf authored Apr 5, 2024
1 parent 0fae207 commit 9938518
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 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,21 @@ 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 {
switch act.(type) {
case ConfigureNode:
hasNetworkAction = true
}
}
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

0 comments on commit 9938518

Please sign in to comment.