Postman - how to run requests in different iterations - collections

I have an issue about running a collection
I have the following:
Collection: Request 1
Request 2
Request 3
What I want: When I run collection, I want Request 1 to be executed 20 times, then after iteration 20 to run Request 2 and after Request 2 is done to run Request 3.
So: Request 1 to run 20 times, Request 2 one time, Request 3 one time
I tried something like (In Tests script of Request 1):
if (pm.info.iteration === pm.info.iterationCount+3) {
postman.setNextRequest("Url of request 1")
}
But it's running 1:1 like Request 1, Request 2, Request 3, Request 1, 2,3... and so on
Do you have any ideas? #I am new to Postman

My idea is creating a variable count_num to manage the loop.
Request 1:
Pre-request: Create count_num if there is no count_num in environment
let count = pm.environment.get("count_num");
if (count === undefined || count === null) {
pm.environment.set("count_num", 19);
}
Test: Check the value of count_num, if count_num = 0, then go Request 2.
let count = pm.environment.get("count_num");
if (count === 0){
pm.environment.unset("count_num");
postman.setNextRequest("Req2");
} else {
pm.environment.set("count_num", count - 1);
postman.setNextRequest("Req1");
}
Note: "Req1" & "Req2" are request name, you can change to fit your actual request name.

Related

How can I rerun only failed scenarios in the feature in Karate API? [duplicate]

I have a request where i get Processing or Submitted in a response parameter if the request is in process or passed respectively.
I am able to poll and get if the status is "Processing" or"Submitted" but after that I am unable to fail the request if still i am not getting the expected status after polling for 5 times.
How can i fail request after certain retries do not provide me expected response?
The answer is in your question,
I assume you are polling using a js function,
If so you can add a boolean return from that, if you condition not met return false or if condition met return true then assert the value returned from your feature file.
* def pollingFunc =
"""
function(x) {
// your polling logic which retrives status
if (status == x) {
return true;
}
else{
return false;
}
}
"""
In feature
* def statusFound = pollingFunc("Processed" )
* assert (statusFound == true)
If the expected status not obtained after polling the assert will fail the test

http4s Received premature EOF

I want to implement an http4s server that receives the content from another service, processes it and return the response.
The original service uses redirects so I added the Follow redirect middleware. I also added the Logger middleware to check the logs produced.
The skeleton of the service is:
implicit val clientResource = BlazeClientBuilder[F](global).resource
val wikidataEntityUrl = "http://www.wikidata.org/entity/Q"
def routes(implicit timer: Timer[F]): HttpRoutes[F] = HttpRoutes.of[F] {
case GET -> Root / "e" / entity => {
val uri = uri"http://www.wikidata.org/entity/" / ("Q" + entity)
val req: Request[F] = Request(uri = uri)
clientResource.use { c => {
val req: Request[F] = Request(Method.GET, uri)
def cb(resp: Response[F]): F[Response[F]] = Ok(resp.bodyAsText)
val redirectClient = Logger(true,true,_ => false)(FollowRedirect[F](10, _ => true)(c))
redirectClient.fetch[Response[F]](req)(cb)
}}}}
When I try to access the service with curl as:
curl -v http://localhost:8080/e/33
The response contains the first part of the original content and finnishes with:
transfer closed with outstanding read data remaining
* Closing connection 0
Looking at the logs, they content the following line:
ERROR o.h.s.blaze.Http1ServerStage$$anon$1 - Error writing body
org.http4s.InvalidBodyException: Received premature EOF.
which suggests that there was an error receiving a premature EOF.
I found a possible answer in this issue: but the answers suggest to use deprecated methods like tohttpService.
I think I would need to rewrite the code using a streams, but I am not sure what's the more idiomatic way to do it. Some suggestions?
I received some help in the http4s gitter channel to use the toHttpApp method instead of the fetch method.
I was also suggested also to pass the client as a parameter.
The resulting code is:
case GET -> Root / "s" / entity => {
val uri = uri"http://www.wikidata.org/entity/" / ("Q" + entity)
val req: Request[F] = Request(Method.GET, uri)
val redirectClient = Logger(true,true,_ => false)(FollowRedirect[F](10, _ => true)(client))
redirectClient.toHttpApp.run(req)
}
and now it works as expected.
The toHttpApp method is intended for use in proxy servers.

How to find URL Registrations (not Reservations)?

Is there a windows command to list the process IDs and Names of application holding a specific URL registration?
I am after the applications that has made registrations under the following URL namespace.
http://localhost:55987/
I am aware that URL Reservations can be listed using
netsh http show urlacl
The reservation states that
Reserved URL : http://localhost:55987/
User: \Everyone
Listen: Yes
Delegate: No
SDDL: D:(A;;GX;;;WD)
But how do I find the registrations made under the reserved URL namespace?
You can find the processId for the registered urls using the following command:
netsh http show servicestate view=requestq verbose=no
It's going to return a table like the following:
Request queue name: Request queue is unnamed.
Version: 2.0
State: Active
Request queue 503 verbosity level: Basic
Max requests: 1000
Number of active processes attached: 1
Process IDs:
3604
URL groups:
URL group ID: F100000040000003
State: Active
Request queue name: Request queue is unnamed.
Number of registered URLs: 1
Registered URLs:
HTTP://+:8022/
Server session ID: F200000020000007
Version: 2.0
State: Active
Request queue name: Request queue is unnamed.
Version: 2.0
State: Active
Request queue 503 verbosity level: Basic
Max requests: 1000
Number of active processes attached: 1
Process IDs:
3604
URL groups:
URL group ID: D400000040001E9C
State: Active
Request queue name: Request queue is unnamed.
Number of registered URLs: 1
Registered URLs:
HTTP://+:3799/API
Server session ID: D6000000200013C1
Version: 2.0
State: Active
I`ve also made a powershell function who parses this output to return an object list.
Result sample:
ProcessId ControllerProcessId RegisteredUrl
--------- ------------------- -------------
1860 HTTP://+:8022/
1020 HTTPS://+:5986/WSMAN/
function Parse-HttpSysReqQueue() {
[string[]]$rawHttpSysQueue = netsh http show servicestate view=requestq verbose=no
$urls = #()
$output = #()
$recordIsOpen = $false
$index = 0
$rawHttpSysQueue | ForEach-Object {
$line = $_
# Whether is the begining of a new request queue record.
$newRecordToken = "Request queue name"
if ($line.StartsWith($newRecordToken)) {
$recordIsOpen = $true
$index++; return
}
# We are iterating through a request-queue record.
if ($recordIsOpen) {
# Obtain Process ID
if ($line.Contains("Process IDs:")) {
$rawPid = $rawHttpSysQueue[$index+1]
if($rawPid.Trim() -match '^\d+$'){
$processId = $rawPid.Trim()
} else {
$processId = $null
}
$index++; return
}
# Obtain Controller Process ID (generally IIS)
if ($line.Contains("Controller process ID:")) {
$controllerProcessId = $line.Split(":")[1].Trim()
$index++; return
}
# Read all registered urls from current record.
if ($line.Contains("Registered URLs:")) {
$urlLineIndex = $index+1
while ($rawHttpSysQueue[$urlLineIndex].Trim().StartsWith("HTTP://") -or $rawHttpSysQueue[$urlLineIndex].Trim().StartsWith("HTTPS://")) {
$urls += $rawHttpSysQueue[$urlLineIndex].Trim()
$urlLineIndex++
}
# Add record to output list.
$urls | ForEach-Object {
$output += New-Object PSObject -Property #{
ProcessId = $processId
RegisteredUrl = $_
ControllerProcessId = $controllerProcessId
}
}
# Already read all the urls from this request-queue, consider the record closed.
$processId = $null
$controllerProcessId = $null
$urls = #()
$recordIsOpen = $false
}
}
$index++
}
return $output
}

Repeating email notifications in Bosun

in notification of Bosun configuration, I set the timeout as 5m i.e. 5 minutes.
I am receiving emails for the interval of either 5 minutes or 10 minutes.
I am not able to debug as why is this happening.
Please help.
notification default {
email =jon#rohit.com
print = true
next = default
timeout = 5m
}
template tags {
subject =`Testing Emails Sample`
body = `<p><strong>Tags</strong>
<table>
{{range $k, $v := .Group}}
{{if eq $k "api"}}
<tr><td>{{$k}} : {{$v}}</td></tr>
{{end}}
{{end}}
</table>`
}
alert testSampleAlert5 {
template = tags
$notes = This alert monitors the percentage of 5XX on arm APIs
crit = 1
warn = 0
warnNotification = default
critNotification = default
}
alert testSampleAlert4 {
template = tags
$notes = This alert monitors the percentage of 5XX on arm APIs
crit = 0
warn = 1
warnNotification = default
critNotification = default
}
What you are encountering is bosun's feature of "chained notifications". The next and timeout parameters specify that the default notification will be triggered again after 5 minutes as you have configured it. Since it references itself, it will trigger every 5 minutes until the alert is acknowledged or closed.
You have a few options if this is not what you want.
Acknowledge the alert on the dashboard. This will stop all notification chains from repeating.
Remove the next parameter if you do not want to be re-notified every 5 minutes, or increase the timeout, or something like that.
What is your desired behaviour?

Nginx Upload Progress module - differing XMLHttpRequest behavior on local instance and webserver

Hi I'm basically doing an uploader and using the nginx upload progress module. What I don't understand is why it is running fine on my local machine on localhost (giving XMLHttpRequest readyState 4, with the javascript progress bar % increases accordingly) but can't seem to get any server response when I deploy it on a server (though it clearly does connect to /progress, keeps giving XMLHttpRequest readyState 1)
just following the usual nginx upload progress module code:
function fetch(uuid) {
req = new XMLHttpRequest();
req.open("GET", "/progress", true);
req.setRequestHeader("X-Progress-ID", uuid);
req.onreadystatechange = function () {
/* checking the state here ..*/
console.log(req.readyState);
console.log(req.status);
if (req.readyState == 4) {
if (req.status == 200) {
/* poor-man JSON parser */
var data = eval(req.responseText);
console.log(data.state);
if (data.state == 'done' || data.state == 'uploading') {
prog = Math.floor(100 * (data.received / data.size));
$("#progressbar").progressbar({value: prog});
$("#percentage").html(prog+"%");
}
if (data.state == 'done' || data.received >= data.size) {
window.clearTimeout(timeout);
}
}
}
}
req.send(null);
};
and here are the console logs:
OK for local nginx instance
[22:12:25.734] POST http://localhost:8080/?X-Progress-ID=5b8702050a784e6604953201e398c99a [HTTP/1.1 200 OK 1335ms]
[22:12:25.677] "initialized"
[22:12:25.838] GET http://localhost:8080/progress [HTTP/1.1 200 OK 0ms]
[22:12:25.783] 2
[22:12:25.783] 200
[22:12:25.784] 3
[22:12:25.784] 200
[22:12:25.784] 4
[22:12:25.784] 200
[22:12:25.784] "uploading"
not OK for test server
[00:16:20.638] POST http://00.mydomain.com/?X-Progress-ID=c65681d605911db0b8da3fb0e436d851 [HTTP/1.1 200 OK 2925ms]
[00:16:20.582] "initialized"
[00:16:20.738] GET http://00.mydomain.com/progress [HTTP/1.1 200 OK 293ms]
[00:16:21.039] GET http://00.mydomain.com/progress [HTTP/1.1 200 OK 304ms]
[00:16:20.979] 1
[00:16:20.979] 0
[00:16:20.979] 1
[00:16:20.979] 0
[00:16:20.979] 1
[00:16:20.980] 0
[00:16:21.341] GET http://00.mydomain.com/progress [HTTP/1.1 200 OK 304ms]
[00:16:21.286] 1
[00:16:21.286] 0
[00:16:21.287] 1
[00:16:21.287] 0
[00:16:21.287] 1
[00:16:21.287] 0
...keeps repeating till upload complete...
Any clues to where my error might be?
Turns out to be an async/sync issue for the GET request to /progress... still investigating the issue so I can use async, but basically when I change
req.open("GET", "/progress", true);
to
req.open("GET", "/progress", false);
it starts working on my server
**UPDATE**: turns out to be a silly typo/cutpaste error, it should be
var req = new XMLHttpRequest();
so somehow the js error behaves differently on local and server instance and is ignored sometimes... now the async upload process (with progress bar and resumable) works yay!
**SIDE NOTE**: the given example on the main Nginx wiki for json parsing
var data = eval(req.responseText);
is really not safe, but I've noticed the nginx upload progress module returns back a wrongly-formatted JSON like
({ "state" : "uploading", "received" : 8671, "size" : 2218274 });
so doing something like this would be better
/* non-poor-man JSON Parser */
var response = req.responseText;
var jsonlen = response.length;
var jsondata = response.slice(1, jsonlen-4); //note returned json is malformed
var data = JSON.parse(jsondata);

Resources