Merge lp:~allenap/maas/parallel-coverage into lp:~maas-committers/maas/trunk

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: 5852
Proposed branch: lp:~allenap/maas/parallel-coverage
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 166 lines (+39/-21)
5 files modified
.bzrignore (+2/-1)
.coveragerc (+13/-2)
.gitignore (+2/-1)
Makefile (+14/-13)
src/maastesting/parallel.py (+8/-4)
To merge this branch: bzr merge lp:~allenap/maas/parallel-coverage
Reviewer Review Type Date Requested Status
Lee Trager (community) Approve
Review via email: mp+320786@code.launchpad.net

Commit message

Collect coverage data when running tests in parallel.

Description of the change

The overhead of always doing this is so low that I didn't even thing it was worth making it optional.

To post a comment you must log in.
Revision history for this message
Lee Trager (ltrager) wrote :

LGTM!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2017-02-17 14:23:04 +0000
3+++ .bzrignore 2017-03-23 12:45:28 +0000
4@@ -3,6 +3,8 @@
5 *.egg-info
6 *.log
7 ./.bzr
8+./.coverage
9+./.coverage.*
10 ./.db.lock
11 ./.failed
12 ./.git
13@@ -18,7 +20,6 @@
14 ./bin
15 ./build
16 ./coverage
17-./coverage.data
18 ./coverage.xml
19 ./db
20 ./develop-eggs
21
22=== modified file '.coveragerc'
23--- .coveragerc 2015-02-27 18:33:32 +0000
24+++ .coveragerc 2017-03-23 12:45:28 +0000
25@@ -1,10 +1,21 @@
26 [run]
27-data_file = coverage.data
28+branch = True
29+source = src
30+omit =
31+ */testing.py
32+ */testing/*
33+ */tests/*
34
35 [report]
36+omit =
37+ src/*/migrations/*
38+ src/maastesting/*
39 exclude_lines =
40 # Have to re-enable the standard pragma
41 pragma: no cover
42-
43 # Don't complain if tests don't hit defensive assertion code:
44 raise NotImplementedError
45+
46+[html]
47+directory = coverage
48+title = Coverage for MAAS
49
50=== modified file '.gitignore'
51--- .gitignore 2017-02-17 14:23:04 +0000
52+++ .gitignore 2017-03-23 12:45:28 +0000
53@@ -3,6 +3,8 @@
54 *.egg-info
55 *.log
56 /.bzr
57+/.coverage
58+/.coverage.*
59 /.db.lock
60 /.failed
61 /.git
62@@ -18,7 +20,6 @@
63 /bin
64 /build
65 /coverage
66-/coverage.data
67 /coverage.xml
68 /db
69 /develop-eggs
70
71=== modified file 'Makefile'
72--- Makefile 2017-03-17 12:05:27 +0000
73+++ Makefile 2017-03-23 12:45:28 +0000
74@@ -223,18 +223,20 @@
75 test+lxd: lxd $(strip $(test-scripts))
76 utilities/isolated-make-test
77
78-test: bin/test.parallel
79+test: bin/test.parallel bin/coverage
80+ @$(RM) .coverage .coverage.*
81 @bin/test.parallel --subprocess-per-core
82+ @bin/coverage combine
83
84 test-serial: $(strip $(test-scripts))
85 @bin/maas-region makemigrations --dry-run --exit && exit 1 ||:
86- @$(RM) coverage.data .failed
87+ @$(RM) .coverage .coverage.* .failed
88 $(foreach test,$^,$(test-template);)
89 @test ! -f .failed
90
91 test-failed: $(strip $(test-scripts))
92 @bin/maas-region makemigrations --dry-run --exit && exit 1 ||:
93- @$(RM) coverage.data .failed
94+ @$(RM) .coverage .coverage.* .failed
95 $(foreach test,$^,$(test-template-failed);)
96 @test ! -f .failed
97
98@@ -268,19 +270,18 @@
99 coverage-report: coverage/index.html
100 sensible-browser $< > /dev/null 2>&1 &
101
102-coverage.xml: bin/coverage coverage.data
103- bin/coverage xml --include 'src/*' -o $@
104+coverage.xml: bin/coverage .coverage
105+ bin/coverage xml -o $@
106
107 coverage/index.html: revno = $(or $(shell bzr revno 2>/dev/null),???)
108-coverage/index.html: bin/coverage coverage.data
109+coverage/index.html: bin/coverage .coverage
110 @$(RM) -r $(@D)
111- bin/coverage html --include 'src/*' \
112- --omit 'src/*/tests/*,src/*/testing/*' \
113- --title "MAAS r$(revno)" --directory $(@D)
114+ bin/coverage html \
115+ --title "Coverage for MAAS r$(revno)" \
116+ --directory $(@D)
117
118-coverage.data:
119- @$(error Use `$(MAKE) test-serial+coverage` to generate coverage \
120- data, or invoke a test script using the `--with-coverage` flag)
121+.coverage:
122+ @$(error Use `$(MAKE) test` to generate coverage)
123
124 lint: \
125 lint-py lint-py-complexity lint-py-imports \
126@@ -409,7 +410,7 @@
127 $(RM) docs/api.rst
128 $(RM) -r docs/_autosummary docs/_build
129 $(RM) -r man/.doctrees
130- $(RM) coverage.data coverage.xml
131+ $(RM) .coverage .coverage.* coverage.xml
132 $(RM) -r coverage
133 $(RM) -r .hypothesis
134 $(RM) -r bin include lib local
135
136=== modified file 'src/maastesting/parallel.py'
137--- src/maastesting/parallel.py 2017-02-17 14:23:04 +0000
138+++ src/maastesting/parallel.py 2017-03-23 12:45:28 +0000
139@@ -52,8 +52,11 @@
140 """
141
142 def extendCommand(self, command):
143- """Extend the command (a tuple) with additional arguments."""
144- return command
145+ """Extend the command (a tuple) with additional arguments.
146+
147+ By default this ensures that coverage data is collected.
148+ """
149+ return ("bin/coverage", "run", "--parallel-mode", *command)
150
151 def run(self, result):
152 with tempfile.NamedTemporaryFile() as log:
153@@ -72,10 +75,11 @@
154 })
155
156 def _run(self, result, log):
157- # Build the script first, which may do nothing (but is quick).
158+ # Build things first, which may do nothing (but is quick).
159 with self.lock:
160 subprocess.check_call(
161- ("make", "--quiet", self.script), stdout=log, stderr=log)
162+ ("make", "--quiet", "bin/coverage", self.script),
163+ stdout=log, stderr=log)
164 # Run the script in a subprocess, capturing subunit output.
165 pread, pwrite = os.pipe()
166 with io.open(pread, "rb") as preader: