Merge lp:~cjwatson/rabbitfixture/ctltimeout-parameter into lp:rabbitfixture

Proposed by Colin Watson
Status: Merged
Merged at revision: 44
Proposed branch: lp:~cjwatson/rabbitfixture/ctltimeout-parameter
Merge into: lp:rabbitfixture
Diff against target: 136 lines (+18/-16)
2 files modified
rabbitfixture/server.py (+17/-12)
rabbitfixture/tests/test_server.py (+1/-4)
To merge this branch: bzr merge lp:~cjwatson/rabbitfixture/ctltimeout-parameter
Reviewer Review Type Date Requested Status
Kristian Glass (community) Approve
LAZR Developers Pending
Review via email: mp+371585@code.launchpad.net

Commit message

Allow changing the default server control timeout.

Description of the change

The default of 15 often seems to not quite be enough for massively-parallel Launchpad tests, but rather than changing the hardcoded value I'd rather make it a parameter.

To post a comment you must log in.
Revision history for this message
Kristian Glass (doismellburning) :
review: Approve

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 2019-03-22 18:01:19 +0000
3+++ rabbitfixture/server.py 2019-08-21 13:58:53 +0000
4@@ -167,14 +167,16 @@
5
6 """
7
8- def __init__(self, config):
9+ def __init__(self, config, ctltimeout=None):
10 """Create a `RabbitServerEnvironment` instance.
11
12 :param config: An object exporting the variables
13 `RabbitServerResources` exports.
14+ :param ctltimeout: Timeout for server control operations.
15 """
16 super(RabbitServerEnvironment, self).__init__()
17 self.config = config
18+ self._ctltimeout = ctltimeout or 15
19
20 def setUp(self):
21 super(RabbitServerEnvironment, self).setUp()
22@@ -212,7 +214,7 @@
23
24 @property
25 def ctltimeout(self):
26- return 15
27+ return self._ctltimeout
28
29 def rabbitctl(self, command, strip=False, timeout=None):
30 """Executes a ``rabbitctl`` command and returns status."""
31@@ -269,7 +271,7 @@
32 class RabbitServerRunner(Fixture):
33 """Run a RabbitMQ server."""
34
35- def __init__(self, config):
36+ def __init__(self, config, ctltimeout=None):
37 """Create a `RabbitServerRunner` instance.
38
39 :param config: An object exporting the variables
40@@ -277,12 +279,13 @@
41 """
42 super(RabbitServerRunner, self).__init__()
43 self.config = config
44+ self._ctltimeout = ctltimeout
45 self.process = None
46
47 def setUp(self):
48 super(RabbitServerRunner, self).setUp()
49 self.environment = self.useFixture(
50- RabbitServerEnvironment(self.config))
51+ RabbitServerEnvironment(self.config, ctltimeout=self._ctltimeout))
52 self._start()
53
54 def is_running(self):
55@@ -344,7 +347,7 @@
56 self._spawn()
57 # Wait for the server to come up: stop when the process is dead, or
58 # the timeout expires, or the server responds.
59- timeout = time.time() + 15
60+ timeout = time.time() + self.environment.ctltimeout
61 while time.time() < timeout and self.is_running():
62 if self.environment.is_node_running():
63 break
64@@ -358,8 +361,8 @@
65 # fails to get together.
66 self.addCleanup(self._stop)
67 # `rabbitctl status` can say a node is up before it is ready to accept
68- # connections. Wait at least 5 more seconds for the node to come up...
69- timeout = max(timeout, time.time() + 5)
70+ # connections. Wait for the node to come up...
71+ timeout = max(timeout, time.time() + self.environment.ctltimeout)
72 while time.time() < timeout and self.check_running():
73 try:
74 self.environment.get_connection().close()
75@@ -384,7 +387,7 @@
76 try:
77 self._request_stop()
78 # Wait for the node to go down...
79- timeout = time.time() + 15
80+ timeout = time.time() + self.environment.ctltimeout
81 while time.time() < timeout:
82 if not self.environment.is_node_running():
83 break
84@@ -396,8 +399,8 @@
85 # Go straight to killing the process directly.
86 timeout = time.time()
87
88- # Wait at least 5 more seconds for the process to end...
89- timeout = max(timeout, time.time() + 5)
90+ # Wait for the process to end...
91+ timeout = max(timeout, time.time() + self.environment.ctltimeout)
92 while time.time() < timeout:
93 if not self.is_running():
94 break
95@@ -427,14 +430,16 @@
96 :ivar runner: The `RabbitServerRunner` that bootstraps the server.
97 """
98
99- def __init__(self, config=None):
100+ def __init__(self, config=None, ctltimeout=None):
101 super(RabbitServer, self).__init__()
102 self.config = config
103+ self._ctltimeout = ctltimeout
104
105 def setUp(self):
106 super(RabbitServer, self).setUp()
107 if self.config is None:
108 self.config = RabbitServerResources()
109 self.useFixture(self.config)
110- self.runner = RabbitServerRunner(self.config)
111+ self.runner = RabbitServerRunner(
112+ self.config, ctltimeout=self._ctltimeout)
113 self.useFixture(self.runner)
114
115=== modified file 'rabbitfixture/tests/test_server.py'
116--- rabbitfixture/tests/test_server.py 2019-03-22 18:01:19 +0000
117+++ rabbitfixture/tests/test_server.py 2019-08-21 13:58:53 +0000
118@@ -76,7 +76,7 @@
119 f.write("while :; do sleep 1 || exit; done\n")
120 os.chmod(fakectlbin, stat.S_IRWXU)
121
122- with RabbitServer() as fixture:
123+ with RabbitServer(ctltimeout=0.1) as fixture:
124 try:
125 connect_arguments = {
126 "host": 'localhost:%s' % fixture.config.port,
127@@ -87,9 +87,6 @@
128 self.useFixture(MonkeyPatch(
129 "rabbitfixture.server.RabbitServerEnvironment.ctlbin",
130 fakectlbin))
131- self.useFixture(MonkeyPatch(
132- "rabbitfixture.server.RabbitServerEnvironment.ctltimeout",
133- 0.1))
134 except Exception:
135 # self.useFixture() is not being used because we want to
136 # handle the fixture's lifecycle, so we must also be

Subscribers

People subscribed via source and target branches

to all changes: