Skip to content

Commit 2cb7ce6

Browse files
committed
[QE]add memory consume track
1 parent 92d5e00 commit 2cb7ce6

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

test/e2e/features/story_openshift.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Feature: 4 Openshift stories
1313
Scenario: Overall cluster health
1414
Given executing "oc new-project testproj" succeeds
1515
And get cpu data "After start"
16+
And get memory data "After start"
1617
When executing "oc apply -f httpd-example.yaml" succeeds
1718
And executing "oc rollout status deployment httpd-example" succeeds
1819
Then stdout should contain "successfully rolled out"
@@ -25,11 +26,13 @@ Feature: 4 Openshift stories
2526
When executing "oc expose svc httpd-example" succeeds
2627
Then stdout should contain "httpd-example exposed"
2728
And get cpu data "After deployment"
29+
And get memory data "After deployment"
2830
When with up to "20" retries with wait period of "5s" http response from "http://httpd-example-testproj.apps-crc.testing" has status code "200"
2931
Then executing "curl -s http://httpd-example-testproj.apps-crc.testing" succeeds
3032
And stdout should contain "Hello CRC!"
3133
When executing "crc stop" succeeds
3234
And get cpu data "After stop"
35+
And get memory data "After stop"
3336
And starting CRC with default bundle succeeds
3437
And checking that CRC is running
3538
And with up to "4" retries with wait period of "1m" http response from "http://httpd-example-testproj.apps-crc.testing" has status code "200"

test/e2e/testsuite/testsuite.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/crc-org/crc/v2/test/extended/util"
3030
"github.com/cucumber/godog"
3131
"github.com/shirou/gopsutil/v4/cpu"
32+
"github.com/shirou/gopsutil/v4/mem"
3233
"github.com/spf13/pflag"
3334
)
3435

@@ -267,6 +268,9 @@ func InitializeScenario(s *godog.ScenarioContext) {
267268
if err := getCPUdata("Before start"); err != nil {
268269
fmt.Printf("Failed to collect CPU data: %v\n", err)
269270
}
271+
if err := getMemoryData("Before start"); err != nil {
272+
fmt.Printf("Failed to collect memory data: %v\n", err)
273+
}
270274
}
271275
}
272276

@@ -577,6 +581,8 @@ func InitializeScenario(s *godog.ScenarioContext) {
577581
EnsureVMPartitionSizeCorrect)
578582
s.Step(`^get cpu data "([^"]*)"`,
579583
getCPUdata)
584+
s.Step(`^get memory data "([^"]*)"`,
585+
getMemoryData)
580586

581587
s.After(func(ctx context.Context, _ *godog.Scenario, err error) (context.Context, error) {
582588

@@ -1327,3 +1333,11 @@ func getCPUdata(content string) error {
13271333
file := filepath.Join(wd, "../test-results/cpu-consume.txt")
13281334
return util.WriteToFile(data, file)
13291335
}
1336+
1337+
func getMemoryData(content string) error {
1338+
v, _ := mem.VirtualMemory()
1339+
data := fmt.Sprintf("%s, UsedPercent: %f%%, Free: %v Mib\n", content, v.UsedPercent, v.Free/1024/1024)
1340+
wd, _ := os.Getwd()
1341+
file := filepath.Join(wd, "../test-results/memory-consume.txt")
1342+
return util.WriteToFile(data, file)
1343+
}

0 commit comments

Comments
 (0)