From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: stefanha@redhat.com, Thomas Huth <thuth@redhat.com>,
Laurent Vivier <lvivier@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH RFC 2/2] netdev: set timeout depending on loadavg
Date: Tue, 7 Nov 2023 04:49:27 -0500 [thread overview]
Message-ID: <eb33ee05432afacce29a70a2e3679aaacef723da.1699350487.git.mst@redhat.com> (raw)
In-Reply-To: <1e64d2a47b63ba7d7f49a23c02c2be91ff5c15fe.1699350487.git.mst@redhat.com>
netdev test keeps failing sometimes.
I don't think we should increase the timeout some more:
let's try something else instead, testing how busy the
system is.
Seems to work for me.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
tests/qtest/netdev-socket.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/tests/qtest/netdev-socket.c b/tests/qtest/netdev-socket.c
index 7ba1eff120..bb99d08b5e 100644
--- a/tests/qtest/netdev-socket.c
+++ b/tests/qtest/netdev-socket.c
@@ -18,6 +18,32 @@
#define CONNECTION_TIMEOUT 120
+static double connection_timeout(void)
+{
+ double load;
+ int ret = getloadavg(&load, 1);
+
+ /*
+ * If we can't get load data, or load is low because we just started
+ * running, assume load of 1 (we are alone in this system).
+ */
+ if (ret < 1 || load < 1.0) {
+ load = 1.0;
+ }
+ /*
+ * No one wants to wait more than 10 minutes for this test. Higher load?
+ * Too bad.
+ */
+ if (load > 10.0) {
+ fprintf(stderr, "Warning: load %f higher than 10 - test might timeout\n",
+ load);
+ load = 10.0;
+ }
+
+ /* if load is high increase timeout as we might not get a chance to run */
+ return load * CONNECTION_TIMEOUT;
+}
+
#define EXPECT_STATE(q, e, t) \
do { \
char *resp = NULL; \
@@ -31,7 +57,7 @@ do { \
if (g_str_equal(resp, e)) { \
break; \
} \
- } while (g_test_timer_elapsed() < CONNECTION_TIMEOUT); \
+ } while (g_test_timer_elapsed() < connection_timeout()); \
g_assert_cmpstr(resp, ==, e); \
g_free(resp); \
} while (0)
--
MST
next prev parent reply other threads:[~2023-11-07 9:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-07 9:49 [PATCH RFC 0/2] dynamic timeout for tests Michael S. Tsirkin
2023-11-07 9:49 ` [PATCH RFC 1/2] osdep: add getloadavg Michael S. Tsirkin
2023-11-07 9:49 ` Michael S. Tsirkin [this message]
2023-11-07 9:57 ` [PATCH RFC 0/2] dynamic timeout for tests Philippe Mathieu-Daudé
2023-11-07 10:00 ` Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=eb33ee05432afacce29a70a2e3679aaacef723da.1699350487.git.mst@redhat.com \
--to=mst@redhat.com \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).