Skip to content

Commit

Permalink
Testing: Add TEST_SELECTOR to Kokoro scripts to allow running a subse…
Browse files Browse the repository at this point in the history
…t of the tests. (#1739)
  • Loading branch information
igorpeshansky authored Jun 20, 2024
1 parent 54b4472 commit df531e1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
18 changes: 11 additions & 7 deletions integration_test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ a firewall that allows connections over port 22 for ssh. It is recommended for
Googlers to use our prebuilt testing project. Ask a teammate (e.g. martijnvs@)
for the project ID.

You will also need a GCS bucket that is used to transfer files onto the
You will also need a GCS bucket that is used to transfer files onto the
testing VMs. This is referred to as `${TRANSFERS_BUCKET}`. For Googlers,
`stackdriver-test-143416-untrusted-file-transfers` is recommended.

Expand Down Expand Up @@ -46,15 +46,15 @@ When the setup steps are complete, you can run ops_agent_test from the
```
make integration_tests PROJECT=${PROJECT} TRANSFERS_BUCKET=${TRANSFERS_BUCKET}
```
Alternatively, you can export `PROJECT` and `TRANSFERS_BUCKET` in your
environment and simply call the target.
You can also specify the `ZONES` and `PLATFORMS` variables if you would like
Alternatively, you can export `PROJECT` and `TRANSFERS_BUCKET` in your
environment and simply call the target.
You can also specify the `ZONES` and `IMAGE_SPECS` variables if you would like
to run the tests on something other than the defaults (`us-central1-b` for
ZONES and `debian-cloud:debian-11` for `PLATFORMS`).
ZONES and `debian-cloud:debian-11` for `IMAGE_SPECS`).

The above command will run the tests against the stable Ops Agent. To test
against a pre-built but unreleased agent, you can use add the
AGENT_PACKAGES_IN_GCS environment variable onto your command like this:
`AGENT_PACKAGES_IN_GCS` environment variable onto your command like this:

```
AGENT_PACKAGES_IN_GCS=gs://ops-agents-public-buckets-test-logs/prod/stackdriver_agents/testing/consumer/ops_agent/build/buster/2068/20220926-132259/result \
Expand Down Expand Up @@ -99,7 +99,7 @@ go test -v ./integration_test \
-test.run="TestThirdPartyApps/.*/(nvml|dcgm)"
```

Make sure the platform you specify is included in the PLATFORMS environment
Make sure the platform you specify is included in the `IMAGE_SPECS` environment
variable.

### Testing Flow
Expand Down Expand Up @@ -130,6 +130,10 @@ The test is designed so that simply modifying files in the
right thing. But we do expect that we will need to make big changes to both the
data directory and the test runner before it is really meeting our needs.

By default, the test will skip any applications that were not
impacted by the currently modified set of files. However, if the modified files
are unrelated to any apps, it assumes that all apps are impacted.

### Adding a new third-party application

You will need to add and modify a few files. Start by adding your new
Expand Down
21 changes: 19 additions & 2 deletions integration_test/third_party_apps_test/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ REPO_SUFFIX: If provided, a package repository suffix to install the agent from.
AGENT_PACKAGES_IN_GCS takes precedence over REPO_SUFFIX.
ARTIFACT_REGISTRY_REGION: If provided, signals to the install scripts that the
above REPO_SUFFIX is an artifact registry repo and specifies what region it
is in.
is in.
*/

package third_party_apps_test

import (
"context"
"embed"
"flag"
"fmt"
"log"
"math"
Expand Down Expand Up @@ -745,10 +746,20 @@ func isCriticalFile(f string) bool {
// integration_test/third_party_apps_test/applications/<appname>/
//
// Checks the extracted app names against the set of all known apps.
// If tests were explicitly selected, or if no app is found as impacted, assume
// all apps are.
func determineImpactedApps(modifiedFiles []string, allApps map[string]metadata.IntegrationMetadata) map[string]bool {
impactedApps := make(map[string]bool)
defer log.Printf("impacted apps: %v", impactedApps)

if flag.Lookup("test.run") != nil {
// Honor explicit test selectors.
for app := range allApps {
impactedApps[app] = true
}
return impactedApps
}

for _, f := range modifiedFiles {
if isCriticalFile(f) {
// Consider all apps as impacted.
Expand All @@ -761,7 +772,6 @@ func determineImpactedApps(modifiedFiles []string, allApps map[string]metadata.I

for _, f := range modifiedFiles {
if strings.HasPrefix(f, "apps/") {

// File names: apps/<f>.go
f := strings.TrimPrefix(f, "apps/")
f = strings.TrimSuffix(f, ".go")
Expand All @@ -782,8 +792,15 @@ func determineImpactedApps(modifiedFiles []string, allApps map[string]metadata.I
// The directories here are already authoritative, no
// need to check against list.
impactedApps[f] = true
}
}

if len(impactedApps) == 0 {
// If none of the apps are impacted, treat all of them as impacted.
for app := range allApps {
impactedApps[app] = true
}
return impactedApps
}
return impactedApps
}
Expand Down
3 changes: 3 additions & 0 deletions kokoro/scripts/test/go_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ go_test_args=(
if [[ "${SHORT:-false}" == "true" ]]; then
go_test_args+=( "-test.short" )
fi
if [[ -n "${TEST_SELECTOR:-}" ]]; then
go_test_args+=( "-test.run=${TEST_SELECTOR}" )
fi

TEST_UNDECLARED_OUTPUTS_DIR="${LOGS_DIR}" \
gotestsum "${gotestsum_args[@]}" \
Expand Down

0 comments on commit df531e1

Please sign in to comment.