git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 7/8] test-simple-ipc: add --token=<token> string option

From
JGJeff Hostetler via GitGitGadget <gitgitgadget@gmail.com>
Date
Mar 4, 2021, 20:17 UTC
Message-ID
<1902c23b87dbf6d4cf44d5a51c10eef539bb1243.1614889047.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.893.git.1614889047.gitgitgadget@gmail.com>
From: Jeff Hostetler <jeffhost@microsoft.com>

Change the `test-tool simple-ipc send` subcommand take a string option rather than assume the last unclaimed value of argv.

This makes it a little less awkward to use after the recent changes that added the `--name=<name>` option.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
---
 t/helper/test-simple-ipc.c | 25 ++++++++++++++++---------
 t/t0052-simple-ipc.sh      | 10 +++++-----
 2 files changed, 21 insertions(+), 14 deletions(-)
diff --git a/t/helper/test-simple-ipc.c b/t/helper/test-simple-ipc.c
index 116c824d7555..4da63fd30c97 100644
--- a/t/helper/test-simple-ipc.c
+++ b/t/helper/test-simple-ipc.c
@@ -217,6 +217,7 @@ struct cl_args
 {
 	const char *subcommand;
 	const char *path;
+	const char *token;
 
 	int nr_threads;
 	int max_wait_sec;
@@ -229,6 +230,7 @@ struct cl_args
 struct cl_args cl_args = {
 	.subcommand = NULL,
 	.path = "ipc-test",
+	.token = NULL,
 
 	.nr_threads = 5,
 	.max_wait_sec = 60,
@@ -467,19 +469,22 @@ static int client__probe_server(void)
 }
 
 /*
- * Send an IPC command to an already-running server daemon and print the
- * response.
+ * Send an IPC command token to an already-running server daemon and
+ * print the response.
  *
- * argv[2] contains a simple (1 word) command that `test_app_cb()` (in
- * the daemon process) will understand.
+ * This is a simple 1 word command/token that `test_app_cb()` (in the
+ * daemon process) will understand.
  */
-static int client__send_ipc(const char *send_token)
+static int client__send_ipc(void)
 {
-	const char *command = send_token ? send_token : "(no-command)";
+	const char *command = "(no-command)";
 	struct strbuf buf = STRBUF_INIT;
 	struct ipc_client_connect_options options
 		= IPC_CLIENT_CONNECT_OPTIONS_INIT;
 
+	if (cl_args.token && *cl_args.token)
+		command = cl_args.token;
+
 	options.wait_if_busy = 1;
 	options.wait_if_not_found = 0;
 
@@ -511,7 +516,9 @@ static int client__stop_server(void)
 	time(&time_limit);
 	time_limit += cl_args.max_wait_sec;
 
-	ret = client__send_ipc("quit");
+	cl_args.token = "quit";
+
+	ret = client__send_ipc();
 	if (ret)
 		return ret;
 
@@ -697,6 +704,7 @@ int cmd__simple_ipc(int argc, const char **argv)
 		OPT_INTEGER(0, "batchsize", &cl_args.batchsize, N_("number of requests per thread")),
 
 		OPT_STRING(0, "byte", &bytevalue, N_("byte"), N_("ballast character")),
+		OPT_STRING(0, "token", &cl_args.token, N_("token"), N_("command token to send to the server")),
 
 		OPT_END()
 	};
@@ -757,10 +765,9 @@ int cmd__simple_ipc(int argc, const char **argv)
 	}
 
 	if (!strcmp(cl_args.subcommand, "send")) {
-		const char *send_token = argv[0];
 		if (client__probe_server())
 			return 1;
-		return !!client__send_ipc(send_token);
+		return !!client__send_ipc();
 	}
 
 	if (!strcmp(cl_args.subcommand, "sendbytes")) {
diff --git a/t/t0052-simple-ipc.sh b/t/t0052-simple-ipc.sh
index 18dcc8130728..ff98be31a51b 100755
--- a/t/t0052-simple-ipc.sh
+++ b/t/t0052-simple-ipc.sh
@@ -20,7 +20,7 @@ test_expect_success 'start simple command server' '
 '
 
 test_expect_success 'simple command server' '
-	test-tool simple-ipc send ping >actual &&
+	test-tool simple-ipc send --token=ping >actual &&
 	echo pong >expect &&
 	test_cmp expect actual
 '
@@ -31,19 +31,19 @@ test_expect_success 'servers cannot share the same path' '
 '
 
 test_expect_success 'big response' '
-	test-tool simple-ipc send big >actual &&
+	test-tool simple-ipc send --token=big >actual &&
 	test_line_count -ge 10000 actual &&
 	grep -q "big: [0]*9999\$" actual
 '
 
 test_expect_success 'chunk response' '
-	test-tool simple-ipc send chunk >actual &&
+	test-tool simple-ipc send --token=chunk >actual &&
 	test_line_count -ge 10000 actual &&
 	grep -q "big: [0]*9999\$" actual
 '
 
 test_expect_success 'slow response' '
-	test-tool simple-ipc send slow >actual &&
+	test-tool simple-ipc send --token=slow >actual &&
 	test_line_count -ge 100 actual &&
 	grep -q "big: [0]*99\$" actual
 '
@@ -116,7 +116,7 @@ test_expect_success 'stress test threads' '
 test_expect_success 'stop-daemon works' '
 	test-tool simple-ipc stop-daemon &&
 	test_must_fail test-tool simple-ipc is-active &&
-	test_must_fail test-tool simple-ipc send ping
+	test_must_fail test-tool simple-ipc send --token=ping
 '
 
 test_done
-- 
gitgitgadget
Previous: Jeff Hostetler via GitGitGadgetNext: Jeff Hostetler via GitGitGadget
Message 3 of 15 in “Simple IPC Cleanups”
  1. 0/8 Simple IPC CleanupsJeff Hostetler via GitGitGadget, Mar 4, 2021
  2. 6/8 test-simple-ipc: refactor command line option processing in helperJeff Hostetler via GitGitGadget, Mar 4, 2021
  3. 7/8 test-simple-ipc: add --token=<token> string optionJeff Hostetler via GitGitGadget, Mar 4, 2021
  4. 4/8 simple-ipc: move error handling up a levelJeff Hostetler via GitGitGadget, Mar 4, 2021
  5. 2/8 unix-socket: simplify initialization of unix_stream_listen_optsJeff Hostetler via GitGitGadget, Mar 4, 2021
  6. Junio C HamanoMar 4, 2021
  7. 3/8 unix-stream-server: create unix-stream-server.cJeff Hostetler via GitGitGadget, Mar 4, 2021
  8. 5/8 unix-stream-server: add st_dev and st_mode to socket stolen checksJeff Hostetler via GitGitGadget, Mar 4, 2021
  9. René ScharfeMar 6, 2021
  10. Jeff HostetlerMar 8, 2021
  11. 1/8 pkt-line: remove buffer arg from write_packetized_from_fd_no_flush()Jeff Hostetler via GitGitGadget, Mar 4, 2021
  12. Junio C HamanoMar 4, 2021
  13. 8/8 simple-ipc: update design documentation with more detailsJeff Hostetler via GitGitGadget, Mar 4, 2021
  14. Junio C HamanoMar 5, 2021
  15. Jeff HostetlerMar 5, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.