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

chore: parallelize unit tests #3081

Merged
merged 1 commit into from
Mar 20, 2023
Merged

Conversation

jonas-jonas
Copy link
Member

Related issue(s)

Checklist

  • I have read the contributing guidelines.
  • I have referenced an issue containing the design document if my change
    introduces a new feature.
  • I am following the
    contributing code guidelines.
  • I have read the security policy.
  • I confirm that this pull request does not address a security
    vulnerability. If this pull request addresses a security vulnerability, I
    confirm that I got the approval (please contact
    [email protected]) from the maintainers to push
    the changes.
  • I have added tests that prove my fix is effective or that my feature
    works.
  • I have added or changed the documentation.

Further Comments

@@ -25,37 +25,37 @@ func mkpw(t *testing.T, length int) []byte {
}
Copy link
Member Author

Choose a reason for hiding this comment

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

From ~35s to ~12s

@@ -30,10 +30,19 @@ import (
"github.com/ory/kratos/selfservice/hook"
Copy link
Member Author

Choose a reason for hiding this comment

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

From ~35s to 1.3s (not a typo 😅)

Reason being that internal.NewFastRegistryWithMocks was running migrations on every sub-test case, which always took around 0.5s - 1s. Also, parallalizing helped a bit too.

Since we are just testing config here, this should be a good change. LMK, if you think otherwise...

testDatabase(t, "cockroach", dockertest.ConnectToTestCockroachDBPop(t))
}

func testDatabase(t *testing.T, db string, c *pop.Connection) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Turn off whitespace diff to see what actually changed here.

testDatabase(t, "mysql", dockertest.ConnectToTestMySQLPop(t))
}

func TestMigrations_Cockroach(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This setup is a lot easier to use. I've had to comment out parts of the old setup from time to time, if say the mysql migrations were failing, and I wanted to debug. Now, I can just click debug on the TestMigrations_Mysql case. WDYT?

@@ -6,7 +6,6 @@ package migratest
import (
Copy link
Member Author

Choose a reason for hiding this comment

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

No real speedup here, just some cleanup.

@codecov
Copy link

codecov bot commented Feb 8, 2023

Codecov Report

Merging #3081 (c6313e2) into master (8210cd0) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head c6313e2 differs from pull request most recent head c34c94f. Consider uploading reports for the commit c34c94f to get more accurate results

@@           Coverage Diff           @@
##           master    #3081   +/-   ##
=======================================
  Coverage   77.62%   77.62%           
=======================================
  Files         317      317           
  Lines       20041    20046    +5     
=======================================
+ Hits        15556    15561    +5     
  Misses       3292     3292           
  Partials     1193     1193           
Impacted Files Coverage Δ
courier/template/testhelpers/testhelpers.go 95.95% <100.00%> (+0.21%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@@ -26,7 +26,7 @@ import (
)
Copy link
Member Author

Choose a reason for hiding this comment

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

These were running for around 5s and are now < 0.5s total.

(They are called by the github.com/ory/kratos/courier/template/email tests, which were running for around 40s and are now at 6.5s)

@@ -224,7 +224,9 @@ func TestWebHooks(t *testing.T) {
},
Copy link
Member Author

Choose a reason for hiding this comment

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

25.608s => 9s

@aeneasr
Copy link
Member

aeneasr commented Mar 17, 2023

What is needed to merge this?

@jonas-jonas jonas-jonas self-assigned this Mar 20, 2023
@jonas-jonas jonas-jonas marked this pull request as ready for review March 20, 2023 07:15
@jonas-jonas jonas-jonas force-pushed the jonas-jonas/test/parallel-tests branch from 9d7a662 to c34c94f Compare March 20, 2023 08:06
@jonas-jonas
Copy link
Member Author

Still some more to go, but let's merge this, and I'll work on the others in separate PRs.

@aeneasr aeneasr merged commit 5403f86 into master Mar 20, 2023
@aeneasr aeneasr deleted the jonas-jonas/test/parallel-tests branch March 20, 2023 10:44
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