Speed up the state tests somewhat. #6296

Merged
merged 5 commits into from Sep 21, 2016

Conversation

Projects
None yet
2 participants
Owner

howbazaar commented Sep 21, 2016

This branch attacks sever tests in particular. I timed a normal test run on my machine, and also with -race.
The worst race results are:
PASS: status_history_test.go:24: StatusHistorySuite.TestPruneStatusHistoryBySize 192.659s
PASS: assign_test.go:1252: assignCleanSuite.TestAssignUnitPolicyConcurrently 65.348s
PASS: assign_test.go:1252: assignCleanSuite.TestAssignUnitPolicyConcurrently 57.833s
PASS: state_test.go:294: MultiEnvStateSuite.TestWatchTwoEnvironments 22.822s

Unfortunately there is very little we can do for TestWatchTwoEnvironments, it is just testing many things.

This branch attacks the other three. TestPruneStatusHistoryBySize is made faster by not inserting history documents one at a time. It makes sense to add a specific method to insert the huge number of documents in batches rather than one at a time. The results after tweaking are:

$ go test -check.v -check.f StatusHistorySuite
PASS: status_history_test.go:50: StatusHistorySuite.TestPruneStatusHistoryByDate 1.447s
PASS: status_history_test.go:25: StatusHistorySuite.TestPruneStatusHistoryBySize 1.373s
PASS: status_history_test.go:142: StatusHistorySuite.TestStatusHistoryFiltersByDateAndDelta 0.072s
OK: 3 passed
PASS
ok github.com/juju/juju/state 3.273s

$ go test -race -check.v -check.f StatusHistorySuite
PASS: status_history_test.go:50: StatusHistorySuite.TestPruneStatusHistoryByDate 6.357s
PASS: status_history_test.go:25: StatusHistorySuite.TestPruneStatusHistoryBySize 8.074s
PASS: status_history_test.go:142: StatusHistorySuite.TestStatusHistoryFiltersByDateAndDelta 0.318s
OK: 3 passed
PASS
ok github.com/juju/juju/state 16.787s

So from 192s down to 8s.

The TestAssignUnitPolicyConcurrently test is actually just doing many runs in parallel. Instead of running 50 units in parallel for the race, just use 10, but keep 50 for the normal test runs.
NOTE: it is running the tests twice because the suite is registered twice with different policies.

$ go test -check.v -check.f TestAssignUnitPolicyConcurrently
PASS: assign_test.go:1252: assignCleanSuite.TestAssignUnitPolicyConcurrently 6.250s
PASS: assign_test.go:1252: assignCleanSuite.TestAssignUnitPolicyConcurrently 6.142s
OK: 2 passed
PASS
ok github.com/juju/juju/state 12.901s

$ go test -race -check.v -check.f TestAssignUnitPolicyConcurrently
PASS: assign_test.go:1252: assignCleanSuite.TestAssignUnitPolicyConcurrently 3.498s
PASS: assign_test.go:1252: assignCleanSuite.TestAssignUnitPolicyConcurrently 3.695s
OK: 2 passed
PASS
ok github.com/juju/juju/state 9.754s

Owner

howbazaar commented Sep 21, 2016

$$merge$$

Contributor

jujubot commented Sep 21, 2016

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

Contributor

jujubot commented Sep 21, 2016

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/9292

Owner

howbazaar commented Sep 21, 2016

$$merge$$

Contributor

jujubot commented Sep 21, 2016

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

Contributor

jujubot commented Sep 21, 2016

Build failed: Tests failed
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/9293

Owner

howbazaar commented Sep 21, 2016

$$merge$$

Contributor

jujubot commented Sep 21, 2016

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

@jujubot jujubot merged commit 51f5186 into juju:master Sep 21, 2016

@howbazaar howbazaar deleted the howbazaar:state-speed branch Sep 21, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment