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

Unified Diff: appengine/swarming/swarming_bot/bot_code/file_refresher_test.py

Issue 2024313003: Send authorization headers when calling Swarming backend. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: rebase Created 4 years, 6 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
Index: appengine/swarming/swarming_bot/bot_code/file_refresher_test.py
diff --git a/appengine/swarming/swarming_bot/bot_code/file_refresher_test.py b/appengine/swarming/swarming_bot/bot_code/file_refresher_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..65f1407df6865aa1895a590e9f58af75472bb67d
--- /dev/null
+++ b/appengine/swarming/swarming_bot/bot_code/file_refresher_test.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+# Copyright 2016 The LUCI Authors. All rights reserved.
+# Use of this source code is governed under the Apache License, Version 2.0
+# that can be found in the LICENSE file.
+
+import json
+import logging
+import os
+import sys
+import tempfile
+import time
+import unittest
+
+import test_env_bot_code
+test_env_bot_code.setup_test_env()
+
+from depot_tools import auto_stub
+from depot_tools import fix_encoding
+from utils import file_path
+
+import file_refresher
+
+
+class TestFileRefresherThread(auto_stub.TestCase):
+ def setUp(self):
+ super(TestFileRefresherThread, self).setUp()
+ self.root_dir = tempfile.mkdtemp(prefix='file_refresher')
+ self.path = os.path.join(self.root_dir, 'target_file')
+
+ def tearDown(self):
+ file_path.rmtree(self.root_dir)
+ super(TestFileRefresherThread, self).tearDown()
+
+ def test_works(self):
+ counter = [0]
+ def callback():
+ counter[0] += 1
+ return counter[0]
+ r = file_refresher.FileRefresherThread(self.path, callback, 0.1)
+ r.start()
+ time.sleep(1)
+ r.stop()
+ self.assertTrue(0 < counter[0] < 15) # was called reasonable number of times
+ with open(self.path, 'rb') as f:
+ body = json.load(f)
+ self.assertEqual(counter[0], body) # actually updated the file
+
+
+if __name__ == '__main__':
+ fix_encoding.fix_encoding()
+ logging.basicConfig(
+ level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL)
+ unittest.main()
« no previous file with comments | « appengine/swarming/swarming_bot/bot_code/file_refresher.py ('k') | appengine/swarming/swarming_bot/bot_code/remote_client.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698