Mailing List Archive

[6.0] 2b75ddaea vtc_http2: Automatic stream identifier
commit 2b75ddaea6553bbf36f132621bc1f058ce172845
Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
Date: Fri Oct 20 18:53:26 2023 +0200

vtc_http2: Automatic stream identifier

diff --git a/bin/varnishtest/tests/a02028.vtc b/bin/varnishtest/tests/a02028.vtc
new file mode 100644
index 000000000..4ba8986ed
--- /dev/null
+++ b/bin/varnishtest/tests/a02028.vtc
@@ -0,0 +1,24 @@
+varnishtest "Automatic stream numbers"
+
+server s1 {
+ loop 4 {
+ stream next {
+ rxreq
+ txresp
+ } -run
+ }
+} -start
+
+client c1 -connect ${s1_sock} {
+ loop 3 {
+ stream next {
+ txreq
+ rxresp
+ } -run
+ }
+
+ stream 7 {
+ txreq
+ rxresp
+ } -run
+} -run
diff --git a/bin/varnishtest/vtc_http.h b/bin/varnishtest/vtc_http.h
index 5cd079890..0d542a2d3 100644
--- a/bin/varnishtest/vtc_http.h
+++ b/bin/varnishtest/vtc_http.h
@@ -63,6 +63,7 @@ struct http {

pthread_t tp;
VTAILQ_HEAD(, stream) streams;
+ unsigned last_stream;
pthread_mutex_t mtx;
pthread_cond_t cond;
struct hpk_ctx *encctx;
diff --git a/bin/varnishtest/vtc_http2.c b/bin/varnishtest/vtc_http2.c
index d4d0443a2..0bc3d3362 100644
--- a/bin/varnishtest/vtc_http2.c
+++ b/bin/varnishtest/vtc_http2.c
@@ -2510,9 +2510,17 @@ stream_thread(void *priv)
static struct stream *
stream_new(const char *name, struct http *h)
{
- char *p;
+ char *p, buf[20];
struct stream *s;

+ if (!strcmp("next", name)) {
+ if (h->last_stream > 0)
+ bprintf(buf, "%d", h->last_stream + 2);
+ else
+ bprintf(buf, "%d", 1);
+ name = buf;
+ }
+
ALLOC_OBJ(s, STREAM_MAGIC);
AN(s);
AZ(pthread_cond_init(&s->cond, NULL));
@@ -2531,6 +2539,7 @@ stream_new(const char *name, struct http *h)

CHECK_OBJ_NOTNULL(h, HTTP_MAGIC);
s->hp = h;
+ h->last_stream = s->id;

//bprintf(s->connect, "%s", "${v1_sock}");
AZ(pthread_mutex_lock(&h->mtx));
@@ -2623,7 +2632,8 @@ stream_run(struct stream *s)
* stream ID [SPEC] [ACTION]
*
* ID is the HTTP/2 stream number, while SPEC describes what will be
- * done in that stream.
+ * done in that stream. If ID has the value ``next``, the actual stream
+ * number is computed based on the last one.
*
* Note that, when parsing a stream action, if the entity isn't operating
* in HTTP/2 mode, these spec is ran before::
@@ -2693,7 +2703,7 @@ cmd_stream(CMD_ARGS)
continue;
}
if (**av == '-')
- vtc_fatal(vl, "Unknown client argument: %s", *av);
+ vtc_fatal(vl, "Unknown stream argument: %s", *av);
REPLACE(s->spec, *av);
}
}
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit