##// END OF EJS Templates
wrap db before host dir is gone in new test
Aleksey Bogdanov -
Show More
@@ -240,56 +240,66 b' def test_get_tail_session_awareness():'
240 tmp_path = Path(tmpdir)
240 tmp_path = Path(tmpdir)
241 hist_file = tmp_path / "history.sqlite"
241 hist_file = tmp_path / "history.sqlite"
242 get_source = lambda x: x[2]
242 get_source = lambda x: x[2]
243
243 hm1 = None
244 # hm1 creates a new session and adds history entries,
244 hm2 = None
245 # ha catches up
245 try:
246 hm1 = HistoryManager(shell=ip, hist_file=hist_file)
246 # hm1 creates a new session and adds history entries,
247 hm1_last_sid = hm1.get_last_session_id
247 # ha catches up
248 ha = HistoryAccessor(hist_file=hist_file)
248 hm1 = HistoryManager(shell=ip, hist_file=hist_file)
249 ha_last_sid = ha.get_last_session_id
249 hm1_last_sid = hm1.get_last_session_id
250
250 ha = HistoryAccessor(hist_file=hist_file)
251 hist1 = ["a=1", "b=1", "c=1"]
251 ha_last_sid = ha.get_last_session_id
252 for i, h in enumerate(hist1 + [""], start=1):
252
253 hm1.store_inputs(i, h)
253 hist1 = ["a=1", "b=1", "c=1"]
254 assert list(map(get_source, hm1.get_tail())) == hist1
254 for i, h in enumerate(hist1 + [""], start=1):
255 assert list(map(get_source, ha.get_tail())) == hist1
255 hm1.store_inputs(i, h)
256 sid1 = hm1_last_sid()
256 assert list(map(get_source, hm1.get_tail())) == hist1
257 assert sid1 is not None
257 assert list(map(get_source, ha.get_tail())) == hist1
258 assert ha_last_sid() == sid1
258 sid1 = hm1_last_sid()
259
259 assert sid1 is not None
260 # hm2 creates a new session and adds entries,
260 assert ha_last_sid() == sid1
261 # ha catches up
261
262 hm2 = HistoryManager(shell=ip, hist_file=hist_file)
262 # hm2 creates a new session and adds entries,
263 hm2_last_sid = hm2.get_last_session_id
263 # ha catches up
264
264 hm2 = HistoryManager(shell=ip, hist_file=hist_file)
265 hist2 = ["a=2", "b=2", "c=2"]
265 hm2_last_sid = hm2.get_last_session_id
266 for i, h in enumerate(hist2 + [""], start=1):
266
267 hm2.store_inputs(i, h)
267 hist2 = ["a=2", "b=2", "c=2"]
268 tail = hm2.get_tail(n=3)
268 for i, h in enumerate(hist2 + [""], start=1):
269 assert list(map(get_source, tail)) == hist2
269 hm2.store_inputs(i, h)
270 tail = ha.get_tail(n=3)
270 tail = hm2.get_tail(n=3)
271 assert list(map(get_source, tail)) == hist2
271 assert list(map(get_source, tail)) == hist2
272 sid2 = hm2_last_sid()
272 tail = ha.get_tail(n=3)
273 assert sid2 is not None
273 assert list(map(get_source, tail)) == hist2
274 assert ha_last_sid() == sid2
274 sid2 = hm2_last_sid()
275 assert sid2 != sid1
275 assert sid2 is not None
276
276 assert ha_last_sid() == sid2
277 # but hm1 still maintains its point of reference
277 assert sid2 != sid1
278 # and adding more entries to it doesn't change others
278
279 # immediate perspective
279 # but hm1 still maintains its point of reference
280 assert hm1_last_sid() == sid1
280 # and adding more entries to it doesn't change others
281 tail = hm1.get_tail(n=3)
281 # immediate perspective
282 assert list(map(get_source, tail)) == hist1
282 assert hm1_last_sid() == sid1
283
283 tail = hm1.get_tail(n=3)
284 hist3 = ["a=3", "b=3", "c=3"]
284 assert list(map(get_source, tail)) == hist1
285 for i, h in enumerate(hist3 + [""], start=5):
285
286 hm1.store_inputs(i, h)
286 hist3 = ["a=3", "b=3", "c=3"]
287 tail = hm1.get_tail(n=7)
287 for i, h in enumerate(hist3 + [""], start=5):
288 assert list(map(get_source, tail)) == hist1 + [""] + hist3
288 hm1.store_inputs(i, h)
289 tail = hm2.get_tail(n=3)
289 tail = hm1.get_tail(n=7)
290 assert list(map(get_source, tail)) == hist2
290 assert list(map(get_source, tail)) == hist1 + [""] + hist3
291 tail = ha.get_tail(n=3)
291 tail = hm2.get_tail(n=3)
292 assert list(map(get_source, tail)) == hist2
292 assert list(map(get_source, tail)) == hist2
293 assert hm1_last_sid() == sid1
293 tail = ha.get_tail(n=3)
294 assert hm2_last_sid() == sid2
294 assert list(map(get_source, tail)) == hist2
295 assert ha_last_sid() == sid2
295 assert hm1_last_sid() == sid1
296 assert hm2_last_sid() == sid2
297 assert ha_last_sid() == sid2
298 finally:
299 if hm1:
300 hm1.save_thread.stop()
301 if hm2:
302 hm2.save_thread.stop()
303 hm = hm1 or hm2
304 if hm:
305 hm.db.close()
General Comments 0
You need to be logged in to leave comments. Login now