62c50b831352f7c6d0927e26f16e71cc98a92656 hiram Tue Apr 23 13:07:16 2019 -0700 now covering all error exits in hubApi.c refs #18869 diff --git src/hg/hubApi/tests/jsonConsumer.pl src/hg/hubApi/tests/jsonConsumer.pl index cf5a32d..7c98d01 100755 --- src/hg/hubApi/tests/jsonConsumer.pl +++ src/hg/hubApi/tests/jsonConsumer.pl @@ -1,50 +1,51 @@ #!/usr/bin/env perl use strict; use warnings; use HTTP::Tiny; use Time::HiRes; use JSON; use Getopt::Long; my $http = HTTP::Tiny->new(); # my $server = 'https://apibeta.soe.ucsc.edu'; # my $server = 'https://api-test.gi.ucsc.edu'; +# my $server="https://genome-euro.ucsc.edu/cgi-bin/loader/hubApi"; my $server = 'https://hgwdev-api.gi.ucsc.edu'; # my $server = 'https://hgwbeta.soe.ucsc.edu/cgi-bin/hubApi'; my $globalHeaders = { 'Content-Type' => 'application/json' }; my $lastRequestTime = Time::HiRes::time(); my $processStartTime = Time::HiRes::time(); my $requestCount = 0; ############################################################################## # command line options my $endpoint = ""; my $hubUrl = ""; my $genome = ""; my $db = ""; my $track = ""; my $chrom = ""; my $start = ""; my $end = ""; my $test0 = 0; my $debug = 0; my $trackLeavesOnly = 0; my $measureTiming = 0; my $jsonOutputArrays = 0; -my $maxItemsOutput = 0; +my $maxItemsOutput = ""; ############################################################################## sub usage() { printf STDERR "usage: ./jsonConsumer.pl [arguments]\n"; printf STDERR "arguments: -test0 - perform test of /list/publicHubs and /list/ucscGenomes endpoints -hubUrl=<URL> - use the URL to access the track or assembly hub -db=<dbName> - use one of the UCSC databases for data access -track=<trackName> - specify a single track in a hub or database -chrom=<chromName> - restrict the operation to a single chromosome -start=<coordinate> - restrict the operation to a range, use both start and end -end=<coordinate> - restrict the operation to a range, use both start and end -maxItemsOutput=<N> - limit output to this number of items. Default 1,000 maximum allowed 1,000,000 -trackLeavesOnly - for list tracks function, no containers listed @@ -123,31 +124,31 @@ $endpoint =~ s#^/##; my $url = "$server/$endpoint"; if(%{$parameters}) { my @params; foreach my $key (keys %{$parameters}) { my $value = $parameters->{$key}; push(@params, "$key=$value"); } my $param_string = join(';', @params); $url.= '?'.$param_string; } if ($debug) { $url .= ";debug=1"; } if ($measureTiming) { $url .= ";measureTiming=1"; } if ($jsonOutputArrays) { $url .= ";jsonOutputArrays=1"; } - if ($maxItemsOutput) { $url .= ";maxItemsOutput=$maxItemsOutput"; } + if (length($maxItemsOutput)) { $url .= ";maxItemsOutput=$maxItemsOutput"; } printf STDERR "### '%s'\n", $url; my $response = $http->get($url, {headers => $headers}); my $status = $response->{status}; if(!$response->{success}) { # Quickly check for rate limit exceeded & Retry-After (lowercase due to our client) if($status == 429 && exists $response->{headers}->{'retry-after'}) { my ($status, $reason) = ($response->{status}, $response->{reason}); my $retry = $response->{headers}->{'retry-after'}; printf STDERR "Failed for $endpoint! Status code: ${status}. Reason: ${reason}, retry-after: $retry seconds\n"; # hashOutput($response->{headers}); Time::HiRes::sleep($retry); # After sleeping see that we re-request return performRestAction($endpoint, $parameters, $headers); } else { @@ -318,31 +319,36 @@ } if (length($track)) { $parameters{"track"} = "$track"; } if (length($chrom)) { $parameters{"chrom"} = "$chrom"; } if (length($start)) { $parameters{"start"} = "$start"; $parameters{"end"} = "$end"; } $jsonReturn = performJsonAction($endpoint, \%parameters); $errReturn = 1 if (defined ($jsonReturn->{'error'})); printf "%s", $json->pretty->encode( $jsonReturn ); } else { - printf STDERR "# endpoint not supported at this time: '%s'\n", $endpoint; +# printf STDERR "# endpoint not supported at this time: '%s'\n", $endpoint; +# Pass along the bogus request just to test the error handling. + my %parameters; + $jsonReturn = performJsonAction($endpoint, \%parameters); + $errReturn = 1 if (defined ($jsonReturn->{'error'})); + printf "%s", $json->pretty->encode( $jsonReturn ); } } else { printf STDERR "ERROR: no endpoint given ?\n"; exit 255; } return $errReturn; } # sub processEndPoint() ########################################################################### ### test /list/publicHubs and /list/ucscGenomes sub test0() { my $json = JSON->new; my $jsonReturn = {};