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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2016 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file.
5
6 import json
7 import logging
8 import os
9 import sys
10 import tempfile
11 import time
12 import unittest
13
14 import test_env_bot_code
15 test_env_bot_code.setup_test_env()
16
17 from depot_tools import auto_stub
18 from depot_tools import fix_encoding
19 from utils import file_path
20
21 import file_refresher
22
23
24 class TestFileRefresher(auto_stub.TestCase):
25 def setUp(self):
26 super(TestFileRefresher, self).setUp()
27 self.root_dir = tempfile.mkdtemp(prefix='file_refresher')
28 self.path = os.path.join(self.root_dir, 'target_file')
29
30 def tearDown(self):
31 file_path.rmtree(self.root_dir)
32 super(TestFileRefresher, self).tearDown()
33
34 def test_works(self):
35 counter = [0]
36 def callback():
37 counter[0] += 1
38 return counter[0]
39 r = file_refresher.FileRefresher(self.path, callback, 0.1)
40 r.start()
41 time.sleep(1)
42 r.stop()
43 self.assertTrue(0 < counter[0] < 15) # was called reasonable number of times
44 with open(self.path, 'rb') as f:
45 body = json.load(f)
46 self.assertEqual(counter[0], body) # actually updated the file
47
48
49 if __name__ == '__main__':
50 fix_encoding.fix_encoding()
51 logging.basicConfig(
52 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL)
53 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698