Commit 5d7f9718 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 8689314b
...@@ -839,7 +839,7 @@ def _watch(twlink, zf, at, pinok, replyok): ...@@ -839,7 +839,7 @@ def _watch(twlink, zf, at, pinok, replyok):
wg.wait() wg.wait()
""" """
def _(ctx): def _(ctx, ev):
reply = twlink.sendReq(ctx, b"watch %s @%s" % (h(zf._p_oid), h(at))) reply = twlink.sendReq(ctx, b"watch %s @%s" % (h(zf._p_oid), h(at)))
if replyok.endswith('…'): if replyok.endswith('…'):
rok = replyok[:-len('…')] rok = replyok[:-len('…')]
...@@ -854,13 +854,13 @@ def _watch(twlink, zf, at, pinok, replyok): ...@@ -854,13 +854,13 @@ def _watch(twlink, zf, at, pinok, replyok):
# doCheckingPin calls f and verifies that wcfs sends expected pins during the # doCheckingPin calls f and verifies that wcfs sends expected pins during the
# time f executes. # time f executes.
# #
# f(ctx) # XXX + ev? # f(ctx, eventv)
# pinokByWLink: {} tWatchLink -> (zf, {} blk -> at). # pinokByWLink: {} tWatchLink -> (zf, {} blk -> at).
# pinfunc(wlink, foid, blk, at) | None. XXX foid -> ZBigFile? # pinfunc(wlink, foid, blk, at) | None. XXX foid -> ZBigFile?
# #
# 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): def doCheckingPin(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.
# #
...@@ -869,14 +869,18 @@ def doCheckingPin(f, pinokByWLink, pinfunc=None): ...@@ -869,14 +869,18 @@ def doCheckingPin(f, pinokByWLink, pinfunc=None):
# we did not received expeced pin when wcfs sends final ok? # we did not received expeced pin when wcfs sends final ok?
ctx, cancel = with_timeout() ctx, cancel = with_timeout()
wg = sync.WorkGroup(ctx) wg = sync.WorkGroup(ctx)
ev = []
for wlink, (zf, pinok) in pinokByWLink.items(): for wlink, (zf, pinok) in pinokByWLink.items():
def _(ctx, wlink): def _(ctx, wlink):
pinv = wlink._expectPin(ctx, zf, pinok) pinv = wlink._expectPin(ctx, zf, pinok)
ev.append('pin rx') # XXX + zf, pin details?
tdelay() # increase probability to receive erroneous extra pins tdelay() # increase probability to receive erroneous extra pins
for p in pinv: if pinfunc is not None:
if pinfunc is not None: for p in pinv:
pinfunc(wlink, p.foid, p.blk, p.at) pinfunc(wlink, p.foid, p.blk, p.at)
ev.append('pin ack pre') # XXX +details?
for p in pinv:
p.reply(b"ack") p.reply(b"ack")
# check that we don't get extra pins before reply to "watch" # check that we don't get extra pins before reply to "watch"
try: try:
...@@ -890,13 +894,15 @@ def doCheckingPin(f, pinokByWLink, pinfunc=None): ...@@ -890,13 +894,15 @@ def doCheckingPin(f, pinokByWLink, pinfunc=None):
wg.go(_, wlink) wg.go(_, wlink)
def _(ctx): def _(ctx):
f(ctx) f(ctx, ev)
# cancel _expectPin waiting upon completing f # cancel _expectPin waiting upon completing f
# -> error that missed pins were not received. # -> error that missed pins were not received.
cancel() cancel()
wg.go(_) wg.go(_)
wg.wait() wg.wait()
return ev
# _expectPin asserts that wcfs sends expected pin messages. # _expectPin asserts that wcfs sends expected pin messages.
# #
...@@ -1067,8 +1073,7 @@ def test_wcfs(): ...@@ -1067,8 +1073,7 @@ def test_wcfs():
blk_data = f.blk(blk) blk_data = f.blk(blk)
assert f.cached()[blk] == 0 assert f.cached()[blk] == 0
ev = [] def _(ctx, ev):
def _(ctx):
assert f.cached()[blk] == 0 assert f.cached()[blk] == 0
ev.append('read pre') ev.append('read pre')
...@@ -1090,7 +1095,7 @@ def test_wcfs(): ...@@ -1090,7 +1095,7 @@ def test_wcfs():
b = _rx b = _rx
ev.append('read ' + chr(b)) ev.append('read ' + chr(b))
doCheckingPin(_, {wl: (zf, pinok)}) ev = doCheckingPin(_, {wl: (zf, pinok)})
""" """
......
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