[7.3] 7d5a519fc vtc_http2: Automatic stream identifier

Simon Stridsberg simon.stridsberg at varnish-software.com
Mon Mar 18 18:23:05 UTC 2024


commit 7d5a519fc608eec76a735d68100b2dab274e854d
Author: Dridi Boukelmoune <dridi.boukelmoune at 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 a5d43001e..c213eae17 100644
--- a/bin/varnishtest/vtc_http.h
+++ b/bin/varnishtest/vtc_http.h
@@ -86,6 +86,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 42410e45f..ecd1ea326 100644
--- a/bin/varnishtest/vtc_http2.c
+++ b/bin/varnishtest/vtc_http2.c
@@ -2639,9 +2639,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));
@@ -2663,6 +2671,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));
@@ -2768,7 +2777,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::
@@ -2837,7 +2847,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);
 	}
 }


More information about the varnish-commit mailing list