##// 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 240 tmp_path = Path(tmpdir)
241 241 hist_file = tmp_path / "history.sqlite"
242 242 get_source = lambda x: x[2]
243
244 # hm1 creates a new session and adds history entries,
245 # ha catches up
246 hm1 = HistoryManager(shell=ip, hist_file=hist_file)
247 hm1_last_sid = hm1.get_last_session_id
248 ha = HistoryAccessor(hist_file=hist_file)
249 ha_last_sid = ha.get_last_session_id
250
251 hist1 = ["a=1", "b=1", "c=1"]
252 for i, h in enumerate(hist1 + [""], start=1):
253 hm1.store_inputs(i, h)
254 assert list(map(get_source, hm1.get_tail())) == hist1
255 assert list(map(get_source, ha.get_tail())) == hist1
256 sid1 = hm1_last_sid()
257 assert sid1 is not None
258 assert ha_last_sid() == sid1
259
260 # hm2 creates a new session and adds entries,
261 # ha catches up
262 hm2 = HistoryManager(shell=ip, hist_file=hist_file)
263 hm2_last_sid = hm2.get_last_session_id
264
265 hist2 = ["a=2", "b=2", "c=2"]
266 for i, h in enumerate(hist2 + [""], start=1):
267 hm2.store_inputs(i, h)
268 tail = hm2.get_tail(n=3)
269 assert list(map(get_source, tail)) == hist2
270 tail = ha.get_tail(n=3)
271 assert list(map(get_source, tail)) == hist2
272 sid2 = hm2_last_sid()
273 assert sid2 is not None
274 assert ha_last_sid() == sid2
275 assert sid2 != sid1
276
277 # but hm1 still maintains its point of reference
278 # and adding more entries to it doesn't change others
279 # immediate perspective
280 assert hm1_last_sid() == sid1
281 tail = hm1.get_tail(n=3)
282 assert list(map(get_source, tail)) == hist1
283
284 hist3 = ["a=3", "b=3", "c=3"]
285 for i, h in enumerate(hist3 + [""], start=5):
286 hm1.store_inputs(i, h)
287 tail = hm1.get_tail(n=7)
288 assert list(map(get_source, tail)) == hist1 + [""] + hist3
289 tail = hm2.get_tail(n=3)
290 assert list(map(get_source, tail)) == hist2
291 tail = ha.get_tail(n=3)
292 assert list(map(get_source, tail)) == hist2
293 assert hm1_last_sid() == sid1
294 assert hm2_last_sid() == sid2
295 assert ha_last_sid() == sid2
243 hm1 = None
244 hm2 = None
245 try:
246 # hm1 creates a new session and adds history entries,
247 # ha catches up
248 hm1 = HistoryManager(shell=ip, hist_file=hist_file)
249 hm1_last_sid = hm1.get_last_session_id
250 ha = HistoryAccessor(hist_file=hist_file)
251 ha_last_sid = ha.get_last_session_id
252
253 hist1 = ["a=1", "b=1", "c=1"]
254 for i, h in enumerate(hist1 + [""], start=1):
255 hm1.store_inputs(i, h)
256 assert list(map(get_source, hm1.get_tail())) == hist1
257 assert list(map(get_source, ha.get_tail())) == hist1
258 sid1 = hm1_last_sid()
259 assert sid1 is not None
260 assert ha_last_sid() == sid1
261
262 # hm2 creates a new session and adds entries,
263 # ha catches up
264 hm2 = HistoryManager(shell=ip, hist_file=hist_file)
265 hm2_last_sid = hm2.get_last_session_id
266
267 hist2 = ["a=2", "b=2", "c=2"]
268 for i, h in enumerate(hist2 + [""], start=1):
269 hm2.store_inputs(i, h)
270 tail = hm2.get_tail(n=3)
271 assert list(map(get_source, tail)) == hist2
272 tail = ha.get_tail(n=3)
273 assert list(map(get_source, tail)) == hist2
274 sid2 = hm2_last_sid()
275 assert sid2 is not None
276 assert ha_last_sid() == sid2
277 assert sid2 != sid1
278
279 # but hm1 still maintains its point of reference
280 # and adding more entries to it doesn't change others
281 # immediate perspective
282 assert hm1_last_sid() == sid1
283 tail = hm1.get_tail(n=3)
284 assert list(map(get_source, tail)) == hist1
285
286 hist3 = ["a=3", "b=3", "c=3"]
287 for i, h in enumerate(hist3 + [""], start=5):
288 hm1.store_inputs(i, h)
289 tail = hm1.get_tail(n=7)
290 assert list(map(get_source, tail)) == hist1 + [""] + hist3
291 tail = hm2.get_tail(n=3)
292 assert list(map(get_source, tail)) == hist2
293 tail = ha.get_tail(n=3)
294 assert list(map(get_source, tail)) == hist2
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