Commit f384b432 authored by Alain Takoudjou's avatar Alain Takoudjou

slapos.grid.promise: fixup! prevent json file corruption while updating data

parent 8e0ca4c2
......@@ -474,7 +474,7 @@ class PromiseLauncher(object):
try:
with open(history_file) as f:
history_dict = json.load(f)
except OSError as e:
except (IOError, OSError) as e:
if e.errno != errno.ENOENT:
raise
except ValueError:
......@@ -507,7 +507,7 @@ class PromiseLauncher(object):
try:
with open(stat_file_path) as f:
stat_dict = json.load(f)
except OSError as e:
except (IOError, OSError) as e:
if e.errno != errno.ENOENT:
raise
except ValueError:
......
......@@ -569,7 +569,7 @@ class RunPromise(GenericPromise):
def test_runpromise_with_currupted_history(self):
promise_name = 'my_promise'
self.configureLauncher()
self.generatePromiseScript('my_promise.py', success=True, periodicity=0.03)
self.generatePromiseScript('my_promise.py', success=True, periodicity=0.02)
self.launcher.run()
self.assertSuccessResult(promise_name)
......@@ -598,7 +598,7 @@ class RunPromise(GenericPromise):
f.write("""{
"data": ["Date, Success,
""")
time.sleep(4)
time.sleep(3)
with self.assertRaises(ValueError):
self.assertSuccessHistoryResult(promise_name)
......@@ -612,6 +612,13 @@ class RunPromise(GenericPromise):
# Statistics data file is not broken anymore
self.assertSuccessStatsResult(1)
# make sure all works after history_file not exists
os.unlink(history_file)
time.sleep(3)
self.launcher.run()
self.assertSuccessHistoryResult(promise_name)
def test_runpromise_no_logdir(self):
promise_name = 'my_promise.py'
# no promise log output dir
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment