Merge lp:~frankban/rabbitfixture/lp4 into lp:rabbitfixture

Proposed by William Grant
Status: Work in progress
Proposed branch: lp:~frankban/rabbitfixture/lp4
Merge into: lp:rabbitfixture
Diff against target: 98 lines (+28/-27) (has conflicts)
2 files modified
rabbitfixture/server.py (+24/-27)
setup.py (+4/-0)
Text conflict in setup.py
To merge this branch: bzr merge lp:~frankban/rabbitfixture/lp4
Reviewer Review Type Date Requested Status
LAZR Developers Pending
Review via email: mp+243936@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

34. By Francesco Banconi

Increased retries. Refactored _stop to use retries.

33. By Francesco Banconi

Using retries in place of timeout.

32. By Francesco Banconi

Bumped version up.

31. By Francesco Banconi

Increased timeout in fixtures.

30. By Benji York

lp-ify version number

29. By Benji York

make the timeouts longer

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'rabbitfixture/server.py'
2--- rabbitfixture/server.py 2014-05-29 12:26:57 +0000
3+++ rabbitfixture/server.py 2014-12-08 02:13:46 +0000
4@@ -287,6 +287,23 @@
5 os.path.basename(self.config.logfile),
6 content_from_file(self.config.logfile))
7
8+ def _retry(self, func, check_func=None, tries=300, sleep=0.3):
9+ for i in range(tries):
10+ if func():
11+ return True
12+ if check_func is not None and not check_func():
13+ return False
14+ time.sleep(sleep)
15+ return False
16+
17+ def _accepts_connections(self):
18+ """Return True if the node accepts connections, False otherwise."""
19+ try:
20+ self.environment.get_connection().close()
21+ except socket.error:
22+ return False
23+ return True
24+
25 def _start(self):
26 """Start the RabbitMQ server."""
27 # Check if Rabbit is already running. In truth this is really to avoid
28@@ -299,12 +316,7 @@
29 self._spawn()
30 # Wait for the server to come up: stop when the process is dead, or
31 # the timeout expires, or the server responds.
32- timeout = time.time() + 15
33- while time.time() < timeout and self.is_running():
34- if self.environment.is_node_running():
35- break
36- time.sleep(0.3)
37- else:
38+ if not self._retry(self.environment.is_node_running, self.is_running):
39 raise Exception(
40 "Timeout waiting for RabbitMQ server to start: log in %r." %
41 (self.config.logfile,))
42@@ -313,16 +325,8 @@
43 # fails to get together.
44 self.addCleanup(self._stop)
45 # `rabbitctl status` can say a node is up before it is ready to accept
46- # connections. Wait at least 5 more seconds for the node to come up...
47- timeout = max(timeout, time.time() + 5)
48- while time.time() < timeout and self.check_running():
49- try:
50- self.environment.get_connection().close()
51- except socket.error:
52- time.sleep(0.1)
53- else:
54- break
55- else:
56+ # connections.
57+ if not self._retry(self._accepts_connections, self.check_running):
58 raise Exception(
59 "Timeout waiting for RabbitMQ node to come up: log in %r." %
60 (self.config.logfile,))
61@@ -338,17 +342,10 @@
62 """Stop the running server. Normally called by cleanups."""
63 self._request_stop()
64 # Wait for the node to go down...
65- timeout = time.time() + 15
66- while time.time() < timeout:
67- if not self.environment.is_node_running():
68- break
69- time.sleep(0.3)
70- else:
71- raise Exception(
72- "Timeout waiting for RabbitMQ node to go down.")
73- # Wait at least 5 more seconds for the process to end...
74- timeout = max(timeout, time.time() + 5)
75- while time.time() < timeout:
76+ if not self._retry(lambda: not self.environment.is_node_running()):
77+ raise Exception("Timeout waiting for RabbitMQ node to go down.")
78+ # Wait at while longer for the process to end...
79+ for i in range(200):
80 if not self.is_running():
81 break
82 self.process.terminate()
83
84=== modified file 'setup.py'
85--- setup.py 2014-05-29 13:19:05 +0000
86+++ setup.py 2014-12-08 02:13:46 +0000
87@@ -6,7 +6,11 @@
88
89 setup(
90 name='rabbitfixture',
91+<<<<<<< TREE
92 version="0.3.5",
93+=======
94+ version="0.3.3-lp-4",
95+>>>>>>> MERGE-SOURCE
96 packages=find_packages('.'),
97 package_dir={'': '.'},
98 include_package_data=True,

Subscribers

People subscribed via source and target branches