Commit 82aa5949 authored by Kirill Smelkov's avatar Kirill Smelkov Committed by Levin Zimmermann

wcfs: tests: Allow to adjust tDB.assertBlk timeout

Currently assertBlk uses default timeout() to wait for READ operation to
complete. That works well everywhere except that in faulty
protection tests wcfs server will first need to wait for its own
pintimeout time to kill the faulty client and only then	return read
result to all non-faulty clients.

This way corresponding test, when one client fails to handle pin
notification well triggered due to READ operations, will need to use
adjusted longer timeout for the good client when doing assertBlk.

Adjust assertBlk to allow specifying custom timeout as preparatory step
for that.

/reviewed-by @levin.zimmermann
/reviewed-on !18
parent 001e2e7e
...@@ -300,11 +300,13 @@ def start_and_crash_wcfs(zurl, mntpt): # -> WCFS ...@@ -300,11 +300,13 @@ def start_and_crash_wcfs(zurl, mntpt): # -> WCFS
# many tests need to be run with some reasonable timeout to detect lack of wcfs # many tests need to be run with some reasonable timeout to detect lack of wcfs
# response. with_timeout and timeout provide syntactic shortcuts to do so. # response. with_timeout and timeout provide syntactic shortcuts to do so.
def with_timeout(parent=context.background()): # -> ctx, cancel def with_timeout(parent=context.background(), dt=None): # -> ctx, cancel
return context.with_timeout(parent, 3*time.second) if dt is None:
dt = 3*time.second
return context.with_timeout(parent, dt)
def timeout(parent=context.background()): # -> ctx def timeout(parent=context.background(), dt=None): # -> ctx
ctx, _ = with_timeout() ctx, _ = with_timeout(parent, dt)
return ctx return ctx
# tdelay is used in places where we need to delay a bit in order to e.g. # tdelay is used in places where we need to delay a bit in order to e.g.
...@@ -798,8 +800,11 @@ class tFile: ...@@ -798,8 +800,11 @@ class tFile:
# #
# The automatic computation of pinokByWLink is verified against explicitly # The automatic computation of pinokByWLink is verified against explicitly
# provided pinokByWLink when it is present. # provided pinokByWLink when it is present.
#
# The whole read operation must complete in specified time.
# The default timeout is used if timeout is not explicitly given.
@func @func
def assertBlk(t, blk, dataok, pinokByWLink=None): def assertBlk(t, blk, dataok, pinokByWLink=None, timeout=None):
# TODO -> assertCtx('blk #%d' % blk) # TODO -> assertCtx('blk #%d' % blk)
def _(): def _():
assertCtx = 'blk #%d' % blk assertCtx = 'blk #%d' % blk
...@@ -812,10 +817,10 @@ class tFile: ...@@ -812,10 +817,10 @@ class tFile:
dataok = b(dataok) dataok = b(dataok)
blkdata, _ = t.tdb._blkDataAt(t.zf, blk, t.at) blkdata, _ = t.tdb._blkDataAt(t.zf, blk, t.at)
assert blkdata == dataok, "computed vs explicit data" assert blkdata == dataok, "computed vs explicit data"
t._assertBlk(blk, dataok, pinokByWLink) t._assertBlk(blk, dataok, pinokByWLink, timeout=timeout)
@func @func
def _assertBlk(t, blk, dataok, pinokByWLink=None, pinfunc=None): def _assertBlk(t, blk, dataok, pinokByWLink=None, pinfunc=None, timeout=None):
assert len(dataok) <= t.blksize assert len(dataok) <= t.blksize
dataok += b'\0'*(t.blksize - len(dataok)) # tailing zeros dataok += b'\0'*(t.blksize - len(dataok)) # tailing zeros
assert blk < t._sizeinblk() assert blk < t._sizeinblk()
...@@ -863,6 +868,9 @@ class tFile: ...@@ -863,6 +868,9 @@ class tFile:
pinokByWLink[wlink] = (t.zf, pinok) pinokByWLink[wlink] = (t.zf, pinok)
# access 1 byte on the block and verify that wcfs sends us correct pins # access 1 byte on the block and verify that wcfs sends us correct pins
ctx, cancel = with_timeout(t.tdb.ctx, timeout)
defer(cancel)
blkview = t._blk(blk) blkview = t._blk(blk)
assert t.cached()[blk] == cached assert t.cached()[blk] == cached
...@@ -901,7 +909,7 @@ class tFile: ...@@ -901,7 +909,7 @@ class tFile:
b = _rx b = _rx
ev.append('read ' + b) ev.append('read ' + b)
ev = doCheckingPin(_, pinokByWLink, pinfunc) ev = doCheckingPin(ctx, _, pinokByWLink, pinfunc)
# XXX hack - wlinks are notified and emit events simultaneously - we # XXX hack - wlinks are notified and emit events simultaneously - we
# check only that events begin and end with read pre/post and that pins # check only that events begin and end with read pre/post and that pins
...@@ -1119,7 +1127,7 @@ def _watch(twlink, zf, at, pinok, replyok): ...@@ -1119,7 +1127,7 @@ def _watch(twlink, zf, at, pinok, replyok):
else: else:
assert reply == replyok assert reply == replyok
doCheckingPin(_, {twlink: (zf, pinok)}) doCheckingPin(timeout(twlink.tdb.ctx), _, {twlink: (zf, pinok)})
# doCheckingPin calls f and verifies that wcfs sends expected pins during the # doCheckingPin calls f and verifies that wcfs sends expected pins during the
...@@ -1131,14 +1139,14 @@ def _watch(twlink, zf, at, pinok, replyok): ...@@ -1131,14 +1139,14 @@ def _watch(twlink, zf, at, pinok, replyok):
# #
# pinfunc is called after pin request is received from wcfs, but before pin ack # pinfunc is called after pin request is received from wcfs, but before pin ack
# is replied back. Pinfunc must not block. # is replied back. Pinfunc must not block.
def doCheckingPin(f, pinokByWLink, pinfunc=None): # -> []event(str) def doCheckingPin(ctx, f, pinokByWLink, pinfunc=None): # -> []event(str)
# call f and check that we receive pins as specified. # call f and check that we receive pins as specified.
# Use timeout to detect wcfs replying less pins than expected. # Use timeout to detect wcfs replying less pins than expected.
# #
# XXX detect not sent pins via ack'ing previous pins as they come in (not # XXX detect not sent pins via ack'ing previous pins as they come in (not
# waiting for all of them) and then seeing that we did not received expected # waiting for all of them) and then seeing that we did not received expected
# pin when f completes? # pin when f completes?
ctx, cancel = with_timeout() ctx, cancel = context.with_cancel(ctx)
wg = sync.WorkGroup(ctx) wg = sync.WorkGroup(ctx)
ev = [] ev = []
......
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