Skip to content

Faster campaigns tests, part 3: clean up & parallelize

Warren Gifford requested to merge mrn/faster-tests-3 into main

Created by: mrnugget

Punchline up front: we're now down from ~15s (see https://github.com/sourcegraph/sourcegraph/issues/16320#issuecomment-738681917) to ~8s!


This does three things.

Two cleanups:

  • Simplify createTestUser to not go through the whole db.User.Create flow, but instead insert two rows into the database directly.
  • Move all test helpers and setup into main_test.go

And one performance improvement:

  • Mark all tests that don't use dbconn.Global as parallel with t.Parallel()

Results

$ for i in $(seq 0 5); do time go test ./enterprise/internal/campaigns -count=1; done
ok      github.com/sourcegraph/sourcegraph/enterprise/internal/campaigns        7.948s
go test ./enterprise/internal/campaigns -count=1  5.38s user 2.37s system 74% cpu 10.430 total
ok      github.com/sourcegraph/sourcegraph/enterprise/internal/campaigns        8.087s
go test ./enterprise/internal/campaigns -count=1  5.27s user 2.31s system 71% cpu 10.536 total
ok      github.com/sourcegraph/sourcegraph/enterprise/internal/campaigns        8.152s
go test ./enterprise/internal/campaigns -count=1  5.21s user 2.31s system 70% cpu 10.609 total
ok      github.com/sourcegraph/sourcegraph/enterprise/internal/campaigns        8.062s
go test ./enterprise/internal/campaigns -count=1  5.27s user 2.47s system 73% cpu 10.575 total
ok      github.com/sourcegraph/sourcegraph/enterprise/internal/campaigns        8.121s
go test ./enterprise/internal/campaigns -count=1  5.24s user 2.38s system 71% cpu 10.627 total
ok      github.com/sourcegraph/sourcegraph/enterprise/internal/campaigns        7.979s
go test ./enterprise/internal/campaigns -count=1  5.35s user 2.39s system 74% cpu 10.434 total

Merge request reports

Loading