Index: sharding_supervisor_unittest.py |
=================================================================== |
--- sharding_supervisor_unittest.py (revision 0) |
+++ sharding_supervisor_unittest.py (revision 0) |
@@ -0,0 +1,83 @@ |
+#!/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 os |
+import subprocess |
+import sys |
+import unittest |
+ |
+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') |
+NUM_CORES = sharding_supervisor.DetectNumCores() |
+SHARDS_PER_CORE = sharding_supervisor.SS_DEFAULT_SHARDS_PER_CORE |
+ |
M-A Ruel
2012/04/05 00:53:58
2 lines.
nsylvain
2012/04/05 01:15:58
Done.
|
+def GenerateExpectedOutput(start, end, num_shards): |
M-A Ruel
2012/04/05 00:53:58
In general, I prefer new code to use PEP8 names.
nsylvain
2012/04/05 01:15:58
Done.
|
+ """Generate the expected stdout and stderr for the dummy test.""" |
+ stdout = '' |
+ for i in range(start, end): |
M-A Ruel
2012/04/05 00:53:58
If I were picky, I'd tell you to use xrange(). You
nsylvain
2012/04/05 01:15:58
Good thing you are not picky.
|
+ stdout += 'Running shard %d of %d\n' % (i, num_shards) |
M-A Ruel
2012/04/05 00:53:58
stdout = ''.join(
'Running shard %d of %d\n' %
nsylvain
2012/04/05 01:15:58
I actually don't find this code more readable and
|
+ 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, |
M-A Ruel
2012/04/05 00:53:58
This kind of alignment makes me sad. :/
nsylvain
2012/04/05 01:15:58
what about this one?
|
+ expected_shards) |
+ p = subprocess.Popen([SHARDING_SUPERVISOR, '--no-color', DUMMY_TEST], |
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
+ |
+ p.wait(); |
M-A Ruel
2012/04/05 00:53:58
; ?
p.wait()?
See http://docs.python.org/library/
nsylvain
2012/04/05 01:15:58
Done.
|
+ self.assertEqual(expected_out, p.stdout.read()) |
+ self.assertEqual(expected_err, p.stderr.read()) |
+ self.assertEqual(0, p.returncode) |
+ |
+ 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(0, p.returncode) |
+ |
+ def testSlaveSharding(self): |
+ """Test the --total-slaves and --slave-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', |
+ '--total-slaves', str(total_shards), |
+ '--slave-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(0, p.returncode) |
+ |
+ |
+if __name__ == '__main__': |
+ unittest.main() |
Property changes on: sharding_supervisor_unittest.py |
___________________________________________________________________ |
Added: svn:executable |
+ * |