Skip to content

Commit 0b70113

Browse files
authored
Merge pull request #1109 from grondo/t4011-improvements
testsuite: fix a couple race conditions in `t4011-match-duration.t`
2 parents 2208821 + 68fd13e commit 0b70113

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

resource/modules/resource_match.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,10 @@ static void update_resource (flux_future_t *f, void *arg)
12591259
*/
12601260
ctx->db->metadata.graph_duration.graph_end =
12611261
std::chrono::system_clock::from_time_t ((time_t) expiration);
1262+
flux_log (ctx->h,
1263+
LOG_INFO,
1264+
"resource expiration updated to %.2f",
1265+
expiration);
12621266
}
12631267
for (auto &kv : ctx->notify_msgs) {
12641268
if ( (rc += flux_respond (ctx->h, kv.second->get_msg (), NULL)) < 0) {

t/scripts/dmesg-grep.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env python3
2+
###############################################################
3+
# Copyright 2019 Lawrence Livermore National Security, LLC
4+
# (c.f. AUTHORS, NOTICE.LLNS, COPYING)
5+
#
6+
# This file is part of the Flux resource manager framework.
7+
# For details, see https://github.com/flux-framework.
8+
#
9+
# SPDX-License-Identifier: LGPL-3.0
10+
###############################################################
11+
#
12+
# Follow Flux dmesg output until a line matches a pattern
13+
#
14+
import argparse
15+
import re
16+
import sys
17+
18+
import flux
19+
from flux.constants import FLUX_RPC_STREAMING
20+
from flux.core.watchers import TimerWatcher
21+
22+
parser = argparse.ArgumentParser(
23+
description="watch the flux dmesg log for a given pattern"
24+
)
25+
parser.add_argument(
26+
"-t",
27+
"--timeout",
28+
help="Timeout with error after some number of seconds",
29+
metavar="SEC",
30+
type=float,
31+
default=1.0,
32+
)
33+
parser.add_argument(
34+
"-v",
35+
"--verbose",
36+
help="Emit each line of dmesg output, not just first matching",
37+
action="count",
38+
default=0,
39+
)
40+
parser.add_argument("pattern")
41+
args = parser.parse_args()
42+
43+
44+
def timer_cb(h, watcher, revents, _arg):
45+
print("Timeout!", file=sys.stderr)
46+
h.reactor_stop_error()
47+
48+
49+
def dmesg_cb(rpc, pattern, verbose=False):
50+
buf = rpc.get_str()
51+
match = pattern.search(buf)
52+
if match:
53+
print(buf)
54+
rpc.flux_handle.reactor_stop()
55+
elif verbose:
56+
print(buf)
57+
rpc.reset()
58+
59+
60+
pattern = re.compile(args.pattern)
61+
62+
h = flux.Flux()
63+
64+
rpc = h.rpc("log.dmesg", {"follow": True}, flags=FLUX_RPC_STREAMING)
65+
rpc.then(dmesg_cb, pattern, verbose=args.verbose)
66+
67+
TimerWatcher(h, args.timeout, timer_cb).start()
68+
if h.reactor_run() < 0:
69+
sys.exit(1)

t/t4011-match-duration.t

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ test_under_flux 2
1212
flux setattr log-stderr-level 1
1313
export FLUX_URI_RESOLVE_LOCAL=t
1414

15+
dmesg_grep="flux python ${SHARNESS_TEST_SRCDIR}/scripts/dmesg-grep.py"
16+
1517
# Ensure fluxion modules are loaded under flux-alloc(1)
1618
test_expect_success 'set FLUX_RC_EXTRA so Fluxion modules are loaded under flux-alloc' '
1719
mkdir rc1.d &&
@@ -102,7 +104,7 @@ test_expect_success FLUX_UPDATE_RUNNING \
102104
id1=$(flux proxy $id flux submit sleep 300) &&
103105
duration1=$(subinstance_get_job_duration $id $id1) &&
104106
test_debug "echo initial duration of subinstance job1 is $duration1" &&
105-
echo $duration1 | jq -e ". < 300" &&
107+
echo $duration1 | jq -e ". <= 300" &&
106108
test_debug "echo updating duration of alloc job +5m" &&
107109
flux update $id duration=+5m &&
108110
test_debug "echo waiting for resource-update event" &&
@@ -111,6 +113,8 @@ test_expect_success FLUX_UPDATE_RUNNING \
111113
exp2=$(subinstance_get_expiration $id) &&
112114
test_debug "echo expiration updated from $exp1 to $exp2" &&
113115
echo $exp2 | jq -e ". == $exp1 + 300" &&
116+
flux proxy $id $dmesg_grep -vt 30 \
117+
\"sched.*resource expiration updated\" &&
114118
id2=$(flux proxy $id flux submit sleep 300) &&
115119
duration2=$(subinstance_get_job_duration $id $id2) &&
116120
test_debug "echo duration of subinstance job2 is $duration2" &&

0 commit comments

Comments
 (0)