Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e: remove the use of test context #1606

Closed

Conversation

raghavendra-talur
Copy link
Member

We remove the need for test context by using t.Run() to create anonymous
test functions and always passing the required parameters to the
required functions.

There are two other related changes in the commit:

  1. By creating one subtest with the combined name of the workload and
    the deployer, we remove the problem where go test was adding a number
    suffix to the subtests.
  2. The name of the workload is changed back to Deployment. This is to
    differentiate it from the Deploy action in the test names.

We can run any combination of workload and deployer. We can also restrict it to any one of the action.

Example:

$ go test -run "TestSuites/Exhaustive/Deployment-rbd-Subscr" ./... -v
?       github.com/ramendr/ramen/e2e/argocd     [no test files]
?       github.com/ramendr/ramen/e2e/deployers  [no test files]
?       github.com/ramendr/ramen/e2e/dractions  [no test files]
?       github.com/ramendr/ramen/e2e/util       [no test files]
?       github.com/ramendr/ramen/e2e/workloads  [no test files]
=== RUN   TestSuites
=== RUN   TestSuites/Exhaustive
=== PAUSE TestSuites/Exhaustive
=== CONT  TestSuites/Exhaustive
=== RUN   TestSuites/Exhaustive/Deployment-rbd-Subscr
=== PAUSE TestSuites/Exhaustive/Deployment-rbd-Subscr
=== CONT  TestSuites/Exhaustive/Deployment-rbd-Subscr
=== RUN   TestSuites/Exhaustive/Deployment-rbd-Subscr/Deploy
=== RUN   TestSuites/Exhaustive/Deployment-rbd-Subscr/Enable
=== RUN   TestSuites/Exhaustive/Deployment-rbd-Subscr/Failover
=== RUN   TestSuites/Exhaustive/Deployment-rbd-Subscr/Relocate
=== RUN   TestSuites/Exhaustive/Deployment-rbd-Subscr/Disable
=== RUN   TestSuites/Exhaustive/Deployment-rbd-Subscr/Undeploy
--- PASS: TestSuites (0.00s)
    --- PASS: TestSuites/Exhaustive (0.02s)
        --- PASS: TestSuites/Exhaustive/Deployment-rbd-Subscr (470.19s)
            --- PASS: TestSuites/Exhaustive/Deployment-rbd-Subscr/Deploy (5.02s)
            --- PASS: TestSuites/Exhaustive/Deployment-rbd-Subscr/Enable (90.07s)
            --- PASS: TestSuites/Exhaustive/Deployment-rbd-Subscr/Failover (215.04s)
            --- PASS: TestSuites/Exhaustive/Deployment-rbd-Subscr/Relocate (125.03s)
            --- PASS: TestSuites/Exhaustive/Deployment-rbd-Subscr/Disable (35.01s)
            --- PASS: TestSuites/Exhaustive/Deployment-rbd-Subscr/Undeploy (0.02s)
PASS
ok      github.com/ramendr/ramen/e2e    470.740s
$ go test -run "TestSuites/Exhaustive/Deployment-rbd-Subscr/Deploy" ./... -v
?       github.com/ramendr/ramen/e2e/argocd     [no test files]
?       github.com/ramendr/ramen/e2e/deployers  [no test files]
?       github.com/ramendr/ramen/e2e/dractions  [no test files]
?       github.com/ramendr/ramen/e2e/util       [no test files]
?       github.com/ramendr/ramen/e2e/workloads  [no test files]
=== RUN   TestSuites
=== RUN   TestSuites/Exhaustive
=== PAUSE TestSuites/Exhaustive
=== CONT  TestSuites/Exhaustive
=== RUN   TestSuites/Exhaustive/Deployment-rbd-Subscr
=== PAUSE TestSuites/Exhaustive/Deployment-rbd-Subscr
=== CONT  TestSuites/Exhaustive/Deployment-rbd-Subscr
=== RUN   TestSuites/Exhaustive/Deployment-rbd-Subscr/Deploy
--- PASS: TestSuites (0.00s)
    --- PASS: TestSuites/Exhaustive (0.02s)
        --- PASS: TestSuites/Exhaustive/Deployment-rbd-Subscr (5.03s)
            --- PASS: TestSuites/Exhaustive/Deployment-rbd-Subscr/Deploy (5.03s)
PASS
ok      github.com/ramendr/ramen/e2e    5.476s
$ go test -run "TestSuites/Exhaustive/Deployment-rbd-Subscr/Enable" ./... -v
?       github.com/ramendr/ramen/e2e/argocd     [no test files]
?       github.com/ramendr/ramen/e2e/deployers  [no test files]
?       github.com/ramendr/ramen/e2e/dractions  [no test files]
?       github.com/ramendr/ramen/e2e/util       [no test files]
?       github.com/ramendr/ramen/e2e/workloads  [no test files]
=== RUN   TestSuites
=== RUN   TestSuites/Exhaustive
=== PAUSE TestSuites/Exhaustive
=== CONT  TestSuites/Exhaustive
=== RUN   TestSuites/Exhaustive/Deployment-rbd-Subscr
=== PAUSE TestSuites/Exhaustive/Deployment-rbd-Subscr
=== CONT  TestSuites/Exhaustive/Deployment-rbd-Subscr
=== RUN   TestSuites/Exhaustive/Deployment-rbd-Subscr/Enable
--- PASS: TestSuites (0.00s)
    --- PASS: TestSuites/Exhaustive (0.02s)
        --- PASS: TestSuites/Exhaustive/Deployment-rbd-Subscr (90.05s)
            --- PASS: TestSuites/Exhaustive/Deployment-rbd-Subscr/Enable (90.05s)
PASS
ok      github.com/ramendr/ramen/e2e    90.487s

We remove the need for test context by using t.Run() to create anonymous
test functions and always passing the required parameters to the
required functions.

There are two other related changes in the commit:

1. By creating one subtest with the combined name of the workload and
   the deployer, we remove the problem where go test was adding a number
   suffix to the subtests.
2. The name of the workload is changed back to Deployment. This is to
   differentiate it from the Deploy action in the test names.

Signed-off-by: Raghavendra Talur <[email protected]>
@raghavendra-talur
Copy link
Member Author

Fixes #1571

@nirs
Copy link
Member

nirs commented Oct 25, 2024

We remove the need for test context by using t.Run() to create anonymous test functions and always passing the required parameters to the required functions.

Did you see #1598?

I planned to replace all the code accepting (Workload, Deployer) to accept a TestContext. This way when we add more stuff to the context, we don't need to change all the functions signatures.

There are two other related changes in the commit:

  1. By creating one subtest with the combined name of the workload and
    the deployer, we remove the problem where go test was adding a number
    suffix to the subtests.

Great!

  1. The name of the workload is changed back to Deployment. This is to
    differentiate it from the Deploy action in the test names.

I think the name of the workload should be something like "rbd-vr" or "rbd-vs" - we don't care much about the actual deployment or busybox, but about the the area we test in ramen.

We can run any combination of workload and deployer. We can also restrict it to any one of the action.

Awesome! I could not make this work before.

@@ -55,7 +55,7 @@ func generateWorkloads([]workloads.Workload) {
Path: GITPATH,
Revision: GITREVISION,
AppName: APPNAME,
Name: fmt.Sprintf("Deploy-%s", suffix),
Name: fmt.Sprintf("Deployment-%s", suffix),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy is indeed confusing. I think the a better way is to remove the "Deploy-" prefix.

@@ -85,52 +85,54 @@ func Exhaustive(t *testing.T) {
w := workload
d := deployer

t.Run(w.GetName(), func(t *testing.T) {
t.Run(w.GetName()+"-"+d.GetName(), func(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a function accepting a workload and deloyer and returning a test name would be little nicer.

testcontext.AddTestContext(t.Name(), w, d)
runTestFlow(t)
testcontext.DeleteTestContext(t.Name(), w, d)
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much better! the previous way was too complicated without any benefit.

t.Run("Deploy", func(t *testing.T) {
if err := d.Deploy(w); err != nil {
t.Fatal("Deploy failed")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not improve the code. Being able to run a sub test defined elsewhere is nicer. It will make it easier to create more flows except this simple flow. I think #1598 is better in this case.

@raghavendra-talur raghavendra-talur force-pushed the rtalur-test-context branch 3 times, most recently from bc818e2 to 450dc2d Compare October 26, 2024 07:08
nirs added a commit to nirs/ramen that referenced this pull request Oct 31, 2024
We had nested loops, creating a sub test for the workload, and then
nesting more sub tests for every deployer. This causes the go test
framework to add "#N" suffix to the sub test name, which make the name
unpredictable and harder to use for running specific tests using the
-run option.

Simplify the way we generated sub tests, so we generate one sub test for
every deployer-workload combination. The sub test name is is the same
name we used for the test namespace and all resources, making it easier
to follow and more consistent.

Because we use deployer-workload format, and not workload-deployer,
switch the loops to match the name format.

Example run showing the new structure:

    --- PASS: TestSuites (0.06s)
        --- PASS: TestSuites/Validate (0.06s)
            --- PASS: TestSuites/Validate/CheckRamenHubOperatorStatus (0.03s)
            --- PASS: TestSuites/Validate/CheckRamenSpokeOperatorStatus (0.03s)
        --- PASS: TestSuites/Exhaustive (6.04s)
            --- SKIP: TestSuites/Exhaustive/disapp-deploy-cephfs-busybox (0.00s)
            --- PASS: TestSuites/Exhaustive/subscr-deploy-cephfs-busybox (431.67s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-cephfs-busybox/Deploy (5.16s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-cephfs-busybox/Enable (155.16s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-cephfs-busybox/Failover (85.08s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-cephfs-busybox/Relocate (150.14s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-cephfs-busybox/Disable (30.03s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-cephfs-busybox/Undeploy (6.10s)
            --- PASS: TestSuites/Exhaustive/subscr-deploy-rbd-busybox (461.77s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-rbd-busybox/Deploy (5.17s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-rbd-busybox/Enable (90.24s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-rbd-busybox/Failover (180.15s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-rbd-busybox/Relocate (150.14s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-rbd-busybox/Disable (30.03s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-rbd-busybox/Undeploy (6.05s)
            --- PASS: TestSuites/Exhaustive/disapp-deploy-rbd-busybox (496.64s)
                --- PASS: TestSuites/Exhaustive/disapp-deploy-rbd-busybox/Deploy (1.39s)
                --- PASS: TestSuites/Exhaustive/disapp-deploy-rbd-busybox/Enable (90.11s)
                --- PASS: TestSuites/Exhaustive/disapp-deploy-rbd-busybox/Failover (179.97s)
                --- PASS: TestSuites/Exhaustive/disapp-deploy-rbd-busybox/Relocate (179.87s)
                --- PASS: TestSuites/Exhaustive/disapp-deploy-rbd-busybox/Disable (30.05s)
                --- PASS: TestSuites/Exhaustive/disapp-deploy-rbd-busybox/Undeploy (15.24s)
            --- PASS: TestSuites/Exhaustive/appset-deploy-cephfs-busybox (600.76s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-cephfs-busybox/Deploy (0.16s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-cephfs-busybox/Enable (150.18s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-cephfs-busybox/Failover (180.16s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-cephfs-busybox/Relocate (240.21s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-cephfs-busybox/Disable (30.03s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-cephfs-busybox/Undeploy (0.02s)
            --- PASS: TestSuites/Exhaustive/appset-deploy-rbd-busybox (696.19s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-rbd-busybox/Deploy (0.16s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-rbd-busybox/Enable (95.34s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-rbd-busybox/Failover (300.39s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-rbd-busybox/Relocate (270.26s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-rbd-busybox/Disable (30.03s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-rbd-busybox/Undeploy (0.02s)

With this change we can run any single test using:

    ./run.sh -run TestSuites/Exhaustive/appset-deploy-cephfs-busybox

We can also run multiple tests, for example all tests using
applicationsets:

    ./run.sh -run TestSuites/Exhaustive/appset

Or all tests using rbd storage:

    ./run.sh -run TestSuites/Exhaustive/rbd

Based on Talur's PR RamenDR#1606, which has also other unrelated changes.

Fixes: RamenDR#1614
Signed-off-by: Nir Soffer <[email protected]>
raghavendra-talur pushed a commit that referenced this pull request Nov 4, 2024
We had nested loops, creating a sub test for the workload, and then
nesting more sub tests for every deployer. This causes the go test
framework to add "#N" suffix to the sub test name, which make the name
unpredictable and harder to use for running specific tests using the
-run option.

Simplify the way we generated sub tests, so we generate one sub test for
every deployer-workload combination. The sub test name is is the same
name we used for the test namespace and all resources, making it easier
to follow and more consistent.

Because we use deployer-workload format, and not workload-deployer,
switch the loops to match the name format.

Example run showing the new structure:

    --- PASS: TestSuites (0.06s)
        --- PASS: TestSuites/Validate (0.06s)
            --- PASS: TestSuites/Validate/CheckRamenHubOperatorStatus (0.03s)
            --- PASS: TestSuites/Validate/CheckRamenSpokeOperatorStatus (0.03s)
        --- PASS: TestSuites/Exhaustive (6.04s)
            --- SKIP: TestSuites/Exhaustive/disapp-deploy-cephfs-busybox (0.00s)
            --- PASS: TestSuites/Exhaustive/subscr-deploy-cephfs-busybox (431.67s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-cephfs-busybox/Deploy (5.16s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-cephfs-busybox/Enable (155.16s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-cephfs-busybox/Failover (85.08s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-cephfs-busybox/Relocate (150.14s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-cephfs-busybox/Disable (30.03s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-cephfs-busybox/Undeploy (6.10s)
            --- PASS: TestSuites/Exhaustive/subscr-deploy-rbd-busybox (461.77s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-rbd-busybox/Deploy (5.17s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-rbd-busybox/Enable (90.24s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-rbd-busybox/Failover (180.15s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-rbd-busybox/Relocate (150.14s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-rbd-busybox/Disable (30.03s)
                --- PASS: TestSuites/Exhaustive/subscr-deploy-rbd-busybox/Undeploy (6.05s)
            --- PASS: TestSuites/Exhaustive/disapp-deploy-rbd-busybox (496.64s)
                --- PASS: TestSuites/Exhaustive/disapp-deploy-rbd-busybox/Deploy (1.39s)
                --- PASS: TestSuites/Exhaustive/disapp-deploy-rbd-busybox/Enable (90.11s)
                --- PASS: TestSuites/Exhaustive/disapp-deploy-rbd-busybox/Failover (179.97s)
                --- PASS: TestSuites/Exhaustive/disapp-deploy-rbd-busybox/Relocate (179.87s)
                --- PASS: TestSuites/Exhaustive/disapp-deploy-rbd-busybox/Disable (30.05s)
                --- PASS: TestSuites/Exhaustive/disapp-deploy-rbd-busybox/Undeploy (15.24s)
            --- PASS: TestSuites/Exhaustive/appset-deploy-cephfs-busybox (600.76s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-cephfs-busybox/Deploy (0.16s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-cephfs-busybox/Enable (150.18s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-cephfs-busybox/Failover (180.16s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-cephfs-busybox/Relocate (240.21s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-cephfs-busybox/Disable (30.03s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-cephfs-busybox/Undeploy (0.02s)
            --- PASS: TestSuites/Exhaustive/appset-deploy-rbd-busybox (696.19s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-rbd-busybox/Deploy (0.16s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-rbd-busybox/Enable (95.34s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-rbd-busybox/Failover (300.39s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-rbd-busybox/Relocate (270.26s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-rbd-busybox/Disable (30.03s)
                --- PASS: TestSuites/Exhaustive/appset-deploy-rbd-busybox/Undeploy (0.02s)

With this change we can run any single test using:

    ./run.sh -run TestSuites/Exhaustive/appset-deploy-cephfs-busybox

We can also run multiple tests, for example all tests using
applicationsets:

    ./run.sh -run TestSuites/Exhaustive/appset

Or all tests using rbd storage:

    ./run.sh -run TestSuites/Exhaustive/rbd

Based on Talur's PR #1606, which has also other unrelated changes.

Fixes: #1614
Signed-off-by: Nir Soffer <[email protected]>
@nirs
Copy link
Member

nirs commented Dec 12, 2024

@raghavendra-talur we can closed this now, all the changes already included.

@raghavendra-talur raghavendra-talur deleted the rtalur-test-context branch February 11, 2025 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants