Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3851)

Unified Diff: bin/cbuildbot_comm_unittest.py

Issue 3165052: Add ability for cbuildbot master to synchronize with cbuildbot slaves. (Closed) Base URL: http://src.chromium.org/git/crosutils.git
Patch Set: Remove extra dep Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bin/cbuildbot_comm.py ('k') | bin/cbuildbot_config.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bin/cbuildbot_comm_unittest.py
diff --git a/bin/cbuildbot_comm_unittest.py b/bin/cbuildbot_comm_unittest.py
new file mode 100755
index 0000000000000000000000000000000000000000..4c95fb6ed072227983ea3aa90bc458c58a866075
--- /dev/null
+++ b/bin/cbuildbot_comm_unittest.py
@@ -0,0 +1,101 @@
+#!/usr/bin/python
+
+# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Units tests for cbuildbot_comm commands."""
+
+import cbuildbot_comm
+import sys
+import threading
+import time
+import unittest
+
+_TEST_CONFIG = {'test_slave' :
+ {'master' : False,
+ 'hostname' : 'localhost',
+ 'important' : True},
+ 'test_master' :
+ {'master' : True,
+ 'important' : False
+ }
+ }
+
+# Reduce timeouts.
+cbuildbot_comm._HEARTBEAT_TIMEOUT = 2
+cbuildbot_comm._MAX_TIMEOUT = 6
+
+class _MasterSendBadStatus(threading.Thread):
+
+ def __init__(self, test_class):
+ threading.Thread.__init__(self)
+ self.test_class = test_class
+
+ def run(self):
+ # Sleep for heartbeat timeout to let slave start up.
+ time.sleep(2)
+ return_value = cbuildbot_comm._SendCommand('localhost', 'bad-command',
+ 'args')
+ self.test_class.assertEqual(return_value,
+ cbuildbot_comm._STATUS_COMMAND_REJECTED)
+
+class _MasterCheckStatusThread(threading.Thread):
+
+ def __init__(self, config, expected_return, test_class):
+ threading.Thread.__init__(self)
+ self.config = config
+ self.expected_return = expected_return
+ self.test_class = test_class
+
+ def run(self):
+ return_value = cbuildbot_comm.HaveSlavesCompleted(self.config)
+ self.test_class.assertEqual(return_value, self.expected_return)
+
+
+class CBuildBotCommTest(unittest.TestCase):
+
+ def testSlaveComplete(self):
+ print >> sys.stderr, '\n>>> Running testSlaveComplete\n'
+ # Master should check statuses in another thread.
+ master_thread = _MasterCheckStatusThread(_TEST_CONFIG, True, self)
+ master_thread.start()
+
+ return_value = cbuildbot_comm.PublishStatus(
+ cbuildbot_comm.STATUS_BUILD_COMPLETE)
+ self.assertEqual(return_value, True)
+
+ def testMasterTimeout(self):
+ print >> sys.stderr, '\n>>> Running testMasterTimeout\n'
+ return_value = cbuildbot_comm.HaveSlavesCompleted(_TEST_CONFIG)
+ self.assertEqual(return_value, False)
+
+ def testSlaveTimeout(self):
+ print >> sys.stderr, '\n>>> Running testSlaveTimeout\n'
+ return_value = cbuildbot_comm.PublishStatus(
+ cbuildbot_comm.STATUS_BUILD_COMPLETE)
+ self.assertEqual(return_value, False)
+
+ def testSlaveFail(self):
+ print >> sys.stderr, '\n>>> Running testSlaveFail\n'
+ # Master should check statuses in another thread.
+ master_thread = _MasterCheckStatusThread(_TEST_CONFIG, False, self)
+ master_thread.start()
+
+ return_value = cbuildbot_comm.PublishStatus(
+ cbuildbot_comm.STATUS_BUILD_FAILED)
+ self.assertEqual(return_value, True)
+
+ def testBadCommand(self):
+ print >> sys.stderr, '\n>>> Running testSendBadCommand\n'
+ # Master should check statuses in another thread.
+ master_thread = _MasterSendBadStatus(self)
+ master_thread.start()
+
+ return_value = cbuildbot_comm.PublishStatus(
+ cbuildbot_comm.STATUS_BUILD_COMPLETE)
+ self.assertEqual(return_value, False)
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « bin/cbuildbot_comm.py ('k') | bin/cbuildbot_config.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698