Skip to content

Commit 76e3722

Browse files
authored
Give Splunk some more time after a restart (#668)
We still observe the CI failing because our test suite restarts Splunk. This change adds a workaround a sleep to let Splunk settle after a restart.
1 parent af4da92 commit 76e3722

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

tests/integration/test_app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def setUp(self):
4040
else:
4141
logging.debug(f"App {self.app_name} already exists. Skipping creation.")
4242
if self.service.restart_required:
43-
self.service.restart(120)
43+
self.restart_splunk()
4444

4545
def tearDown(self):
4646
super().tearDown()

tests/integration/test_service.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
class ServiceTestCase(testlib.SDKTestCase):
2828
def test_autologin(self):
2929
service = client.connect(autologin=True, **self.opts.kwargs)
30-
self.service.restart(timeout=120)
30+
self.restart_splunk()
3131
reader = service.jobs.oneshot("search index=internal | head 1")
3232
self.assertIsNotNone(reader)
3333

@@ -128,7 +128,7 @@ def test_parse_fail(self):
128128

129129
def test_restart(self):
130130
service = client.connect(**self.opts.kwargs)
131-
self.service.restart(timeout=300)
131+
self.restart_splunk()
132132
service.login() # Make sure we are awake
133133

134134
def test_read_outputs_with_type(self):
@@ -139,11 +139,11 @@ def test_read_outputs_with_type(self):
139139
self.assertTrue("tcp", entity.content.type)
140140

141141
if service.restart_required:
142-
self.restartSplunk()
142+
self.restart_splunk()
143143
service = client.connect(**self.opts.kwargs)
144144
client.Entity(service, "data/outputs/tcp/syslog/" + name).delete()
145145
if service.restart_required:
146-
self.restartSplunk()
146+
self.restart_splunk()
147147

148148
def test_splunk_version(self):
149149
service = client.connect(**self.opts.kwargs)
@@ -259,7 +259,7 @@ def test_autologin_with_cookie(self):
259259
**self.opts.kwargs,
260260
)
261261
self.assertTrue(service.has_cookies())
262-
self.service.restart(timeout=120)
262+
testlib.restart_splunk(self.service)
263263
reader = service.jobs.oneshot("search index=internal | head 1")
264264
self.assertIsNotNone(reader)
265265

@@ -351,7 +351,8 @@ def test_update_settings(self):
351351
settings.refresh()
352352
updated = settings["sessionTimeout"]
353353
self.assertEqual(updated, original)
354-
self.restartSplunk()
354+
if self.service.restart_required:
355+
self.restart_splunk()
355356

356357

357358
class TestTrailing(unittest.TestCase):

tests/testlib.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ def wait(predicate, timeout=60, pause_time=0.5):
7676
logging.debug("wait finished after %s seconds", datetime.now() - start)
7777

7878

79+
def restart_splunk(service: client.Service):
80+
service.restart(timeout=120)
81+
# Give Splunk some additional time. In our test suite, a subsequent
82+
# restart shortly after the initial restart can cause Splunk to crash
83+
# and fail to start.
84+
sleep(15)
85+
86+
7987
class SDKTestCase(unittest.TestCase):
8088
restart_already_required = False
8189
installedApps = []
@@ -138,6 +146,9 @@ def check_entity(self, entity):
138146
continue
139147
raise
140148

149+
def restart_splunk(self):
150+
restart_splunk(self.service)
151+
141152
def clear_restart_message(self):
142153
"""Tell Splunk to forget that it needs to be restarted.
143154
@@ -175,7 +186,7 @@ def install_app_from_collection(self, name):
175186
if he.status == 400:
176187
raise IOError(f"App {name} not found in app collection")
177188
if self.service.restart_required:
178-
self.service.restart(120)
189+
self.restart_splunk()
179190
self.installedApps.append(name)
180191

181192
def app_collection_installed(self):
@@ -221,20 +232,14 @@ def pathInApp(self, appName, pathComponents):
221232
appPath = separator.join([splunkHome, "etc", "apps", appName] + pathComponents)
222233
return appPath
223234

224-
def restartSplunk(self, timeout=240):
225-
if self.service.restart_required:
226-
self.service.restart(timeout)
227-
else:
228-
raise NoRestartRequiredError()
229-
230235
@classmethod
231236
def setUpClass(cls):
232237
cls.opts = parse([], {}, ".env")
233238
cls.opts.kwargs.update({"retries": 3})
234239
# Before we start, make sure splunk doesn't need a restart.
235240
service = client.connect(**cls.opts.kwargs)
236241
if service.restart_required:
237-
service.restart(timeout=120)
242+
self.restart_splunk()
238243

239244
def setUp(self):
240245
unittest.TestCase.setUp(self)
@@ -244,7 +249,7 @@ def setUp(self):
244249
# and restart. That way we'll be sane for the rest of
245250
# the test.
246251
if self.service.restart_required:
247-
self.restartSplunk()
252+
self.restart_splunk()
248253
logging.debug(
249254
"Connected to splunkd version %s",
250255
".".join(str(x) for x in self.service.splunk_version),

0 commit comments

Comments
 (0)