From 7a387c7a30af150b314cd43566abeb277418852f Mon Sep 17 00:00:00 2001 From: Steve Chavez Date: Thu, 18 Jan 2024 20:03:01 -0500 Subject: [PATCH] nix: add parallel-curl wrapper (#3172) stock curl doesn't make it easy to make many parallel requests to a single endpoint. The endpoint has to be repeated N times. ``` curl --parallel https://example.com https://example.com .. ``` This provides a wrapper for parallel curl. It's useful for testing scenarios like pool timeouts. ``` parallel-curl N https://example.com ``` --- nix/tools/withTools.nix | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/nix/tools/withTools.nix b/nix/tools/withTools.nix index 29bbc990f..79c9802ca 100644 --- a/nix/tools/withTools.nix +++ b/nix/tools/withTools.nix @@ -324,6 +324,31 @@ let done ''; + parallelCurl = + checkedShellScript + { + name = "parallel-curl"; + docs = "wrapper for using parallel curl requests on the same "; + args = [ + "ARG_POSITIONAL_SINGLE([num], [number of parallel requests])" + "ARG_POSITIONAL_SINGLE([host], [host])" + "ARG_LEFTOVERS([extra arguments for curl])" + ]; + } + '' + curl_command="${curl}/bin/curl --parallel --parallel-immediate " + curl_command+="''${_arg_leftovers[*]} " + + x=1 + while [ $x -le "$1" ] + do + curl_command+="$_arg_host " + x=$((x + 1)) + done + + eval "$curl_command" + ''; + withPgrst = checkedShellScript { @@ -381,7 +406,7 @@ in buildToolbox { name = "postgrest-with"; - tools = [ withPgAll withGit withPgrst withSlowPg withSlowPgrst ] ++ withPgVersions; + tools = [ withPgAll withGit withPgrst withSlowPg withSlowPgrst parallelCurl ] ++ withPgVersions; # make withTools available for other nix files extra = { inherit withGit withPg withPgAll withPgrst withSlowPg withSlowPgrst; }; }