Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions test/e2e/features/story_openshift.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Feature: 4 Openshift stories
@darwin @linux @windows @testdata @story_health @needs_namespace
Scenario: Overall cluster health
Given executing "oc new-project testproj" succeeds
And get cpu data "After start"
And get memory data "After start"
When executing "oc apply -f httpd-example.yaml" succeeds
And executing "oc rollout status deployment httpd-example" succeeds
Then stdout should contain "successfully rolled out"
Expand All @@ -23,10 +25,14 @@ Feature: 4 Openshift stories
Then stdout should contain "httpd-example exposed"
When executing "oc expose svc httpd-example" succeeds
Then stdout should contain "httpd-example exposed"
And get cpu data "After deployment"
And get memory data "After deployment"
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"
Then executing "curl -s http://httpd-example-testproj.apps-crc.testing" succeeds
And stdout should contain "Hello CRC!"
When executing "crc stop" succeeds
And get cpu data "After stop"
And get memory data "After stop"
And starting CRC with default bundle succeeds
And checking that CRC is running
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"
Expand Down
47 changes: 47 additions & 0 deletions test/e2e/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
crcCmd "github.com/crc-org/crc/v2/test/extended/crc/cmd"
"github.com/crc-org/crc/v2/test/extended/util"
"github.com/cucumber/godog"
"github.com/shirou/gopsutil/v4/cpu"
"github.com/shirou/gopsutil/v4/mem"
"github.com/spf13/pflag"
)

Expand Down Expand Up @@ -261,6 +263,15 @@ func InitializeScenario(s *godog.ScenarioContext) {
os.Exit(1)
}
}

if tag.Name == "@story_health" {
if err := getCPUdata("Before start"); err != nil {
fmt.Printf("Failed to collect CPU data: %v\n", err)
}
if err := getMemoryData("Before start"); err != nil {
fmt.Printf("Failed to collect memory data: %v\n", err)
}
}
}

return ctx, nil
Expand Down Expand Up @@ -568,6 +579,10 @@ func InitializeScenario(s *godog.ScenarioContext) {
EnsureApplicationIsAccessibleViaNodePort)
s.Step(`^persistent volume of size "([^"]*)"GB exists$`,
EnsureVMPartitionSizeCorrect)
s.Step(`^get cpu data "([^"]*)"`,
getCPUdata)
s.Step(`^get memory data "([^"]*)"`,
getMemoryData)

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

Expand Down Expand Up @@ -1304,3 +1319,35 @@ func deserializeListBlockDeviceCommandOutputToExtractPVSize(lsblkOutput string)
}
return diskSize - (lvmSize + 1), nil
}

func getCPUdata(content string) error {
cpuData, err := cpu.Percent(0, false)
if err != nil {
return fmt.Errorf("failed to get CPU data: %v", err)
}
if len(cpuData) == 0 {
return fmt.Errorf("no CPU data available")
}
data := fmt.Sprintf("%s: %.2f%%\n", content, cpuData)
wd, _ := os.Getwd()
file := filepath.Join(wd, "../test-results/cpu-consume.txt")
return util.WriteToFile(data, file)
}

func getMemoryData(content string) error {
v, err := mem.VirtualMemory()
if err != nil {
return fmt.Errorf("failed to get memory data: %v", err)
}
if v == nil {
return fmt.Errorf("no memory data available")
}
data := fmt.Sprintf("%s, UsedPercent: %.2f%%, Free: %d MiB\n", content, v.UsedPercent, v.Free/1024/1024)

wd, err := os.Getwd()
if err != nil {
return fmt.Errorf("failed to get working directory: %v", err)
}
file := filepath.Join(wd, "../test-results/memory-consume.txt")
return util.WriteToFile(data, file)
}
2 changes: 1 addition & 1 deletion test/extended/util/fileops.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func CreateFile(fileName string) error {
}

func WriteToFile(text string, fileName string) error {
file, err := os.OpenFile(fileName, os.O_RDWR, 0644)
file, err := os.OpenFile(fileName, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
return err
}
Expand Down
Loading