-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutorial-50-suman-parallelism.html
executable file
·307 lines (210 loc) · 11.7 KB
/
tutorial-50-suman-parallelism.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Tutorial: Complete explanation of Suman parallelism</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Tutorial: Complete explanation of Suman parallelism</h1>
<section>
<header>
<h2>Complete explanation of Suman parallelism</h2>
</header>
<article>
<p>This is an area where Suman really shines and has a lot of advantages over AVA etc.</p>
<p>I want to start with a super awesome example of how Suman rocks the party; personally I like to start with
a concrete example before speaking on generic or abstract terms, I learn better that way.</p>
<p>So here is the skeleton of our example test suite (copy it and run it).</p>
<pre class="prettyprint source lang-js"><code>const suman = require('suman');
const Test = suman.init(module, {});
//remember, we can use arrow functions everywhere except describes, since describes are responsible for
//creating a new context and binding it to the callback.
Test.describe('Zulu', {parallel: false}, function () { //root suite is *not* parallel (aka series)
this.describe('A', {parallel: true}, function () {
});
this.describe('B', {parallel: true}, function () {
});
this.describe('C', {parallel: true}, function () {
});
this.describe('D', {parallel: true}, function () {
});
});</code></pre><p>You can see the pattern right? We have 4 child suites which are declared parallel and the 1 parent suite (the root suite)
is declared as being "series" because {parallel:false} for a parent will mean the child suites all run in series.</p>
<p>So now, let's flesh it out:</p>
<pre class="prettyprint source lang-js"><code>const suman = require('suman');
const Test = suman.init(module, {});
Test.describe('Zulu', {parallel: false}, function () { //parent is series (parallel:false)
this.describe('A', {parallel: true}, function () {
this.it(this.desc + '1', t => {
setTimeout(function () {
t.done();
}, 800);
});
this.it(this.desc + '2', t => {
setTimeout(function () {
t.done();
}, 800);
});
});
this.describe('B', {parallel: true}, function () {
this.it(this.desc + '1', t => {
setTimeout(function () {
t.done();
}, 500);
});
this.it(this.desc + '2', t => {
setTimeout(function () {
t.done();
}, 500);
});
});
this.describe('C', {parallel: true}, function () {
this.it(this.desc + '1', t => {
setTimeout(function () {
t.done();
}, 300);
});
this.it(this.desc + '2', t => {
setTimeout(function () {
t.done();
}, 300);
});
});
this.describe('D', {parallel: true}, function () {
this.it(this.desc + '1', t => {
setTimeout(function () {
t.done();
}, 100);
});
this.it(this.desc + '2', t => {
setTimeout(function () {
t.done();
}, 100);
});
});
});</code></pre><p>As you can see above, each child suite's test cases ran in parallel, but the 4 child suites were actually run
series. If they were run in parallel, then we would expect D's test cases to finish first. And now we flip the switch,
and we can see that D's test cases do in fact finish first, if we make the parent parallel:</p>
<pre class="prettyprint source lang-js"><code>const suman = require('suman');
const Test = suman.init(module, {});
Test.describe('Zulu', {parallel: true}, function () { //now we make the parent parallel
this.describe('A', {parallel: true}, function () {
this.it(this.desc + '1', t => {
setTimeout(function () {
t.done();
}, 800);
});
this.it(this.desc + '2', t => {
setTimeout(function () {
t.done();
}, 800);
});
});
this.describe('B', {parallel: true}, function () {
this.it(this.desc + '1', t => {
setTimeout(function () {
t.done();
}, 500);
});
this.it(this.desc + '2', t => {
setTimeout(function () {
t.done();
}, 500);
});
});
this.describe('C', {parallel: true}, function () {
this.it(this.desc + '1', t => {
setTimeout(function () {
t.done();
}, 300);
});
this.it(this.desc + '2', t => {
setTimeout(function () {
t.done();
}, 300);
});
});
this.describe('D', {parallel: true}, function () {
this.it(this.desc + '1', t => {
setTimeout(function () {
t.done();
}, 100);
});
this.it(this.desc + '2', t => {
setTimeout(function () {
t.done();
}, 100);
});
});
});</code></pre><p>See the difference in the output? Play with this example and you will see the pattern.</p>
<p>The pattern is explained below.</p>
<p>So, what are the rules for how the parallel option works in Suman?
There are two places in Suman tests where we can choose something to run in parallel or in series.</p>
<p>Those two places are:</p>
<ol>
<li><p><code>Test.describe/this.describe('Foo', {parallel:false}, function(){});</code></p>
</li>
<li><p><code>this.it('foo', {parallel:true}, function(){});</code></p>
</li>
</ol>
<p>(What about hooks? beforeEach/afterEach hooks run in series for a single test case, but in parallel across test cases; before/after hooks always run in series.) </p>
<p>Here are the rules above how these operate.
Let's start with case 2. For "it" test case functions, if "it" is declared as parallel, it will run in parallel with any other test case that is also declared parallel.
It's that simple for it test cases</p>
<p>In the case of 1, for describes, declaring the describe block as parallel has two different effects.</p>
<ol>
<li>It switches the default for of any of the test cases that directly belong to that describe block.
Normally, to declare a test case as parallel we have to use {parallel:true}. However, if the containing describe suite
is declared parallel, then by default all the of the test cases will be run in parallel, unless they explicitly use
parallel:false.</li>
</ol>
<p>Here is an example:</p>
<pre class="prettyprint source lang-js"><code>Test.describe('A', function(){
this.describe('B', function(){
//we stub the test cases out just for brevity's sake
this.it('a'); //runs in series
this.it('b'); //runs in series
this.it('c'); //runs in series
});
});
Test.describe('A', function(){
this.describe('B', {parallel: true}, function(){
//now, because the containing describe suite is declared parallel, all test cases default to parallel,
//which can be convenient if you don't want to have to add {parallel: true} to each test case
this.it('a'); //runs in parallel with other test cases
this.it('b'); //runs in parallel with other test cases
this.it('c'); //runs in parallel with other test cases
});
});
and of course, to complete the picture, we can
Test.describe('A', function(){
this.describe('B', {parallel: true}, function(){
//now, because the containing describe suite is declared parallel, all test cases default to parallel,
//which can be convenient if you don't want to have to add {parallel: true} to each test case
this.it('a'); //runs in parallel with other test cases
this.it('b', {parallel:false}); //runs first, then the other two tests run in parallel
this.it('c'); //runs in parallel with other test cases
});
});</code></pre><p>Now, let's get really nasty, let's do some more nesting to see what happens. To be continued.</p>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Tutorials</h3><ul><li><a href="tutorial-00-about.html">About Suman</a></li><li><a href="tutorial-01-getting-started.html">Getting Started with Suman</a></li><li><a href="tutorial-02-simple-examples.html">Simple Examples</a></li><li><a href="tutorial-03-high-level-overview.html">Higher Level Overview</a></li><li><a href="tutorial-04-command-line-options.html">Command line options</a></li><li><a href="tutorial-05-advanced-use.html">Advanced Use</a></li><li><a href="tutorial-06-suman-config-file.html">06-suman-config-file</a></li><li><a href="tutorial-07-suman-patterns-and-recipes.html">Suman Patterns and Recipes</a></li><li><a href="tutorial-08-suman-anti-patterns.html">Suman Anti-Patterns</a></li><li><a href="tutorial-09-suman-reporters.html">Suman reporters and creating custom reporters</a></li><li><a href="tutorial-10-dependency-injection.html">10-dependency-injection</a></li><li><a href="tutorial-11-advanced-installation.html">Advanced installation of Suman</a></li><li><a href="tutorial-12-using-suman-with-babel.html">Using Suman with Babel</a></li><li><a href="tutorial-13-test-dir-organization.html">How to organize your test directory</a></li><li><a href="tutorial-14-debugging-suman.html">How to debug Suman tests</a></li><li><a href="tutorial-15-testing-child-processes-with-suman.html">Testing and debugging processes that spawn child processes</a></li><li><a href="tutorial-16-using-spies-with-suman.html">Using test spies with Suman</a></li><li><a href="tutorial-17-suman-server-and-web-reporter.html">About Suman server and built-in web reporter</a></li><li><a href="tutorial-18-tips-and-tricks.html">Tips and tricks</a></li><li><a href="tutorial-19-converting-from-mocha.html">Converting from Mocha to Suman</a></li><li><a href="tutorial-21-running-suman-against-shell-scripts.html">21-running-suman-against-shell-scripts</a></li><li><a href="tutorial-22-case-studies.html">22-case-studies</a></li><li><a href="tutorial-22-programmatic-usage-and-macros.html">22-programmatic-usage-and-macros</a></li><li><a href="tutorial-27-suman-best-practices.html">Best practices with Suman</a></li><li><a href="tutorial-30-anatomy-of-suman-suite.html">Anatomy of Suman Test Suites</a></li><li><a href="tutorial-31-workflows-with-suman.html">Workflows with Suman => Watchers and transpilation</a></li><li><a href="tutorial-40-integrating-with-ci-cd.html">Integrating with CI/CD</a></li><li><a href="tutorial-41-suman-exit-codes.html">List of Suman exit codes</a></li><li><a href="tutorial-42-hidden-secret-features.html">Some secret / hidden features of Suman</a></li><li><a href="tutorial-50-suman-parallelism.html">Complete explanation of Suman parallelism</a></li><li><a href="tutorial-70-usage-with-code-coverage-tools.html">Usage with code coverage tools (namely Istanbul)</a></li><li><a href="tutorial-90-roadmap.html">Suman roadmap and upcoming efforts</a></li><li><a href="tutorial-99-faq.html">FAQ</a></li><li><a href="tutorial-advanced-parallelization-2.html">advanced-parallelization-2</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Wed Feb 08 2017 22:39:23 GMT-0800 (PST)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>