|
OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 """Verify basic usage of sharding_supervisor.""" | |
7 | |
8 import subprocess | |
9 import sys | |
10 import os | |
11 import unittest | |
12 import re | |
cmp
2012/04/04 23:00:28
sort in alphabetic order
nsylvain
2012/04/04 23:24:34
Gotta talk to the guy who wrote the code I stole t
| |
13 | |
14 import sharding_supervisor | |
15 | |
16 SHARDING_SUPERVISOR = os.path.join(os.path.dirname(sys.argv[0]), | |
17 'sharding_supervisor.py') | |
18 DUMMY_TEST = os.path.join(os.path.dirname(sys.argv[0]), 'dummy_test.py') | |
19 | |
cmp
2012/04/04 23:00:28
can this line be removed?
nsylvain
2012/04/04 23:24:34
Done.
| |
20 NUM_CORES = sharding_supervisor.DetectNumCores() | |
21 SHARDS_PER_CORE = sharding_supervisor.SS_DEFAULT_SHARDS_PER_CORE | |
cmp
2012/04/04 23:00:28
can these be sorted in order?
nsylvain
2012/04/04 23:24:34
what order?
| |
22 | |
23 def GenerateExpectedOutput(start, end, num_shards): | |
24 """Generate the expected stdout and stderr for the dummy test.""" | |
25 stdout = '' | |
26 for i in range(start, end): | |
27 stdout += 'Running shard %d of %d\n' % (i, num_shards) | |
28 stderr = '\nALL SHARDS PASSED!\nALL TESTS PASSED!\n' | |
29 | |
30 return (stdout, stderr) | |
31 | |
32 | |
33 class ShardingSupervisorUnittest(unittest.TestCase): | |
34 def testBasicRun(self): | |
35 # Default test. | |
36 expected_shards = NUM_CORES * SHARDS_PER_CORE | |
37 (expected_out, expected_err) = GenerateExpectedOutput(0, expected_shards, | |
38 expected_shards) | |
39 p = subprocess.Popen([SHARDING_SUPERVISOR, '--no-color', DUMMY_TEST], | |
40 stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
41 | |
42 p.wait(); | |
43 self.assertEqual(expected_out, p.stdout.read()) | |
44 self.assertEqual(expected_err, p.stderr.read()) | |
45 self.assertEqual(p.returncode, 0) | |
cmp
2012/04/04 23:00:28
to stay consistent, let's put 0 on the left side a
nsylvain
2012/04/04 23:24:34
Done.
| |
46 | |
47 def testShardPerCore(self): | |
48 """Test the --shards_per_core parameter.""" | |
49 expected_shards = NUM_CORES * 25 | |
50 (expected_out, expected_err) = GenerateExpectedOutput(0, expected_shards, | |
51 expected_shards) | |
52 p = subprocess.Popen([SHARDING_SUPERVISOR, '--no-color', | |
53 '--shards_per_core', '25', DUMMY_TEST], | |
54 stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
55 | |
56 p.wait(); | |
57 self.assertEqual(expected_out, p.stdout.read()) | |
58 self.assertEqual(expected_err, p.stderr.read()) | |
59 self.assertEqual(p.returncode, 0) | |
cmp
2012/04/04 23:00:28
same as above
nsylvain
2012/04/04 23:24:34
Done.
| |
60 | |
61 def testSlaveSharding(self): | |
62 """Test the --suite-total-shards and --suite-shard-index parameters.""" | |
63 total_shards = 6 | |
64 expected_shards = NUM_CORES * SHARDS_PER_CORE * total_shards | |
65 | |
66 # Test every single index to make sure they run correctly. | |
67 for index in range(total_shards): | |
68 begin = NUM_CORES * SHARDS_PER_CORE * index | |
69 end = begin + NUM_CORES * SHARDS_PER_CORE | |
70 (expected_out, expected_err) = GenerateExpectedOutput(begin, end, | |
71 expected_shards) | |
72 p = subprocess.Popen([SHARDING_SUPERVISOR, '--no-color', | |
73 '--suite-total-shards', str(total_shards), | |
74 '--suite-shard-index', str(index), | |
75 DUMMY_TEST], | |
76 stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
77 | |
78 p.wait(); | |
79 self.assertEqual(expected_out, p.stdout.read()) | |
80 self.assertEqual(expected_err, p.stderr.read()) | |
81 self.assertEqual(p.returncode, 0) | |
cmp
2012/04/04 23:00:28
same as above
nsylvain
2012/04/04 23:24:34
Done.
| |
82 | |
83 | |
84 if __name__ == '__main__': | |
85 unittest.main() | |
OLD | NEW |