Commit edfaa116 authored by Levin Zimmermann's avatar Levin Zimmermann

wcfs/pintimeout_kill: Fix killed testing if successful

In case 'test_wcfs_pintimeout_kill' is successful, WCFS kills the
client process. In order to prevent WCFS from killing the full
testing process, we therefore need to encapsulate the test code into
a subprocess, so that only this subprocess is killed in case of a
success.
parent ba39a3ec
...@@ -44,6 +44,7 @@ import sys, os, os.path, subprocess ...@@ -44,6 +44,7 @@ import sys, os, os.path, subprocess
from thread import get_ident as gettid from thread import get_ident as gettid
from time import gmtime from time import gmtime
from errno import EINVAL, ENOTCONN from errno import EINVAL, ENOTCONN
from multiprocessing import Process, Value
from resource import setrlimit, getrlimit, RLIMIT_MEMLOCK from resource import setrlimit, getrlimit, RLIMIT_MEMLOCK
from golang import go, chan, select, func, defer, error, b from golang import go, chan, select, func, defer, error, b
from golang import context, errors, sync, time from golang import context, errors, sync, time
...@@ -1463,31 +1464,50 @@ def test_wcfs_pintimeout_kill(): ...@@ -1463,31 +1464,50 @@ def test_wcfs_pintimeout_kill():
f = t.open(zf) f = t.open(zf)
f.assertData(['','','c2']) f.assertData(['','','c2'])
# XXX move into subprocess not to kill whole testing # move into subprocess to avoid killing testing process, in
ctx, _ = context.with_timeout(context.background(), 2*tkill) # case test is successful
def test(state):
wl = t.openwatch() try:
wg = sync.WorkGroup(ctx) _test(state)
def _(ctx): except Exception:
# send watch. The pin handler won't be replying -> we should never get reply here. state.value = 3
wl.sendReq(ctx, b"watch %s @%s" % (h(zf._p_oid), h(at1)))
fail("watch request completed (should not as pin handler is stuck)")
wg.go(_)
def _(ctx):
req = wl.recvReq(ctx)
assert req is not None
assert req.msg == b"pin %s #%d @%s" % (h(zf._p_oid), 2, h(at1))
# sleep > wcfs pin timeout - wcfs must kill us def _test(state):
_, _rx = select( ctx, _ = context.with_timeout(context.background(), 2*tkill)
ctx.done().recv, # 0 wl = t.openwatch()
time.after(tkill).recv, # 1 wg = sync.WorkGroup(ctx)
) def _(ctx):
if _ == 0: # send watch. The pin handler won't be replying -> we should never get reply here.
raise ctx.err() wl.sendReq(ctx, b"watch %s @%s" % (h(zf._p_oid), h(at1)))
fail("wcfs did not killed stuck client") state.value = 1
wg.go(_) wg.go(_)
wg.wait() def _(ctx):
req = wl.recvReq(ctx)
assert req is not None
assert req.msg == b"pin %s #%d @%s" % (h(zf._p_oid), 2, h(at1))
# sleep > wcfs pin timeout - wcfs must kill us
_, _rx = select(
ctx.done().recv, # 0
time.after(tkill).recv, # 1
)
if _ == 0:
raise ctx.err()
state.value = 2
wg.go(_)
wg.wait()
state = Value("b", 0)
p = Process(target=test, args=(state,))
p.start()
p.join()
if state.value != 0:
state = (
"watch request completed (should not as pin handler is stuck)",
"wcfs did not killed stuck client",
"error in test code",
)[state.value - 1]
fail(state)
# watch with @at > head - must wait for head to become >= at. # watch with @at > head - must wait for head to become >= at.
......
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