Skip to content

Commit 6593320

Browse files
authored
[system tests] Allow setting an optional prefix for the service TestRunID (#2744)
This PR allows to customize the Service TestRunID used in system tests to include a prefix string. This prefix is defined via environment variable "ELASTIC_PACKAGE_PREFIX_SERVICE_TEST_RUN_ID"
1 parent be35e60 commit 6593320

File tree

7 files changed

+22
-8
lines changed

7 files changed

+22
-8
lines changed

internal/common/helpers.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ func ToStringSlice(val interface{}) ([]string, error) {
5858
}
5959

6060
func CreateTestRunID() string {
61-
return fmt.Sprintf("%d", rand.Intn(testRunMaxID-testRunMinID)+testRunMinID)
61+
return CreateTestRunIDWithPrefix("")
62+
}
63+
64+
func CreateTestRunIDWithPrefix(prefix string) string {
65+
return fmt.Sprintf("%s%d", prefix, rand.Intn(testRunMaxID-testRunMinID)+testRunMinID)
6266
}
6367

6468
func ProcessResourceApplyResults(results resource.ApplyResults) string {

internal/testrunner/runners/system/tester.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ var (
136136
enableIndependentAgentsEnv = environment.WithElasticPackagePrefix("TEST_ENABLE_INDEPENDENT_AGENT")
137137
dumpScenarioDocsEnv = environment.WithElasticPackagePrefix("TEST_DUMP_SCENARIO_DOCS")
138138
fieldValidationTestMethodEnv = environment.WithElasticPackagePrefix("FIELD_VALIDATION_TEST_METHOD")
139+
prefixServiceTestRunIDEnv = environment.WithElasticPackagePrefix("PREFIX_SERVICE_TEST_RUN_ID")
139140
)
140141

141142
type fieldValidationMethod int
@@ -483,7 +484,12 @@ func (r *tester) createServiceInfo() (servicedeployer.ServiceInfo, error) {
483484
svcInfo.Name = r.testFolder.Package
484485
svcInfo.Logs.Folder.Local = r.locationManager.ServiceLogDir()
485486
svcInfo.Logs.Folder.Agent = ServiceLogsAgentDir
486-
svcInfo.Test.RunID = common.CreateTestRunID()
487+
488+
prefix := ""
489+
if v, found := os.LookupEnv(prefixServiceTestRunIDEnv); found && v != "" {
490+
prefix = v
491+
}
492+
svcInfo.Test.RunID = common.CreateTestRunIDWithPrefix(prefix)
487493

488494
if r.runTearDown || r.runTestsOnly {
489495
logger.Debug("Skip creating output directory")

test/packages/parallel/terraform_local/data_stream/local/_dev/deploy/tf/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
resource "local_file" "log" {
22
source = "./files/example.log"
3-
filename = "/tmp/service_logs/file.log"
3+
filename = "/tmp/service_logs/file-${var.TEST_RUN_ID}.log"
44
file_permission = "0777"
55
}
66

test/packages/parallel/terraform_local/data_stream/local/_dev/deploy/tf/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ variable "ENVIRONMENT" {
2020
variable "REPO" {
2121
default = "unknown-repo-name"
2222
}
23+
24+
variable "TEST_RUN_ID" {
25+
default = "detached"
26+
}

test/packages/parallel/terraform_local/data_stream/local/_dev/test/system/test-default-config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ wait_for_data_timeout: 1m
22
data_stream:
33
vars:
44
paths:
5-
- "{{ SERVICE_LOGS_DIR }}/file.log"
5+
- "{{ SERVICE_LOGS_DIR }}/file-{{ TEST_RUN_ID }}.log"
66
- "{{ SERVICE_LOGS_DIR }}/file_vars.log"
77
assert:
88
hit_count: 2

test/packages/parallel/terraform_local/data_stream/outputs/_dev/deploy/tf/main.tf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
variable "TEST_RUN_ID" {
2-
default = "detached"
3-
}
4-
51
resource "local_file" "log" {
62
source = "./files/example.log"
73
filename = "/tmp/service_logs/${var.TEST_RUN_ID}.log"

test/packages/parallel/terraform_local/data_stream/outputs/_dev/deploy/tf/variables.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ variable "ENVIRONMENT" {
2020
variable "REPO" {
2121
default = "unknown-repo-name"
2222
}
23+
24+
variable "TEST_RUN_ID" {
25+
default = "detached"
26+
}

0 commit comments

Comments
 (0)