Index: sharding_supervisor_unittest.py |
=================================================================== |
--- sharding_supervisor_unittest.py (revision 0) |
+++ sharding_supervisor_unittest.py (revision 0) |
@@ -0,0 +1,85 @@ |
+#!/usr/bin/env python |
+# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+"""Verify basic usage of sharding_supervisor.""" |
+ |
+import subprocess |
+import sys |
+import os |
+import unittest |
+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
|
+ |
+import sharding_supervisor |
+ |
+SHARDING_SUPERVISOR = os.path.join(os.path.dirname(sys.argv[0]), |
+ 'sharding_supervisor.py') |
+DUMMY_TEST = os.path.join(os.path.dirname(sys.argv[0]), 'dummy_test.py') |
+ |
cmp
2012/04/04 23:00:28
can this line be removed?
nsylvain
2012/04/04 23:24:34
Done.
|
+NUM_CORES = sharding_supervisor.DetectNumCores() |
+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?
|
+ |
+def GenerateExpectedOutput(start, end, num_shards): |
+ """Generate the expected stdout and stderr for the dummy test.""" |
+ stdout = '' |
+ for i in range(start, end): |
+ stdout += 'Running shard %d of %d\n' % (i, num_shards) |
+ stderr = '\nALL SHARDS PASSED!\nALL TESTS PASSED!\n' |
+ |
+ return (stdout, stderr) |
+ |
+ |
+class ShardingSupervisorUnittest(unittest.TestCase): |
+ def testBasicRun(self): |
+ # Default test. |
+ expected_shards = NUM_CORES * SHARDS_PER_CORE |
+ (expected_out, expected_err) = GenerateExpectedOutput(0, expected_shards, |
+ expected_shards) |
+ p = subprocess.Popen([SHARDING_SUPERVISOR, '--no-color', DUMMY_TEST], |
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
+ |
+ p.wait(); |
+ self.assertEqual(expected_out, p.stdout.read()) |
+ self.assertEqual(expected_err, p.stderr.read()) |
+ 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.
|
+ |
+ def testShardPerCore(self): |
+ """Test the --shards_per_core parameter.""" |
+ expected_shards = NUM_CORES * 25 |
+ (expected_out, expected_err) = GenerateExpectedOutput(0, expected_shards, |
+ expected_shards) |
+ p = subprocess.Popen([SHARDING_SUPERVISOR, '--no-color', |
+ '--shards_per_core', '25', DUMMY_TEST], |
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
+ |
+ p.wait(); |
+ self.assertEqual(expected_out, p.stdout.read()) |
+ self.assertEqual(expected_err, p.stderr.read()) |
+ self.assertEqual(p.returncode, 0) |
cmp
2012/04/04 23:00:28
same as above
nsylvain
2012/04/04 23:24:34
Done.
|
+ |
+ def testSlaveSharding(self): |
+ """Test the --suite-total-shards and --suite-shard-index parameters.""" |
+ total_shards = 6 |
+ expected_shards = NUM_CORES * SHARDS_PER_CORE * total_shards |
+ |
+ # Test every single index to make sure they run correctly. |
+ for index in range(total_shards): |
+ begin = NUM_CORES * SHARDS_PER_CORE * index |
+ end = begin + NUM_CORES * SHARDS_PER_CORE |
+ (expected_out, expected_err) = GenerateExpectedOutput(begin, end, |
+ expected_shards) |
+ p = subprocess.Popen([SHARDING_SUPERVISOR, '--no-color', |
+ '--suite-total-shards', str(total_shards), |
+ '--suite-shard-index', str(index), |
+ DUMMY_TEST], |
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
+ |
+ p.wait(); |
+ self.assertEqual(expected_out, p.stdout.read()) |
+ self.assertEqual(expected_err, p.stderr.read()) |
+ self.assertEqual(p.returncode, 0) |
cmp
2012/04/04 23:00:28
same as above
nsylvain
2012/04/04 23:24:34
Done.
|
+ |
+ |
+if __name__ == '__main__': |
+ unittest.main() |
Property changes on: sharding_supervisor_unittest.py |
___________________________________________________________________ |
Added: svn:executable |
+ * |