Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripts at collection level are repeated when using bru.setNextRequest() #3715

Open
2 tasks done
amaulave opened this issue Dec 31, 2024 · 3 comments
Open
2 tasks done
Assignees
Labels
bug Something isn't working module-collection-runner

Comments

@amaulave
Copy link

I have checked the following:

  • I use the newest version of bruno.
  • I've searched existing issues and found nothing related to my issue.

Describe the bug

Bruno version: 1.37.0

I use bru.setNextRequest() function in a request post response script to make a loop on this request until a condition is met. I also have a post response script at collection level to factorize common code to all my requests.

When running the collection, the script at collection level is executed multiple times for the same request when it is repeated by bru.setNextRequest()

Each time my request is run again by bru.setNextRequest(), the collection level script is executed N times where N is the number of repetitions.

.bru file to reproduce the bug

Small example of a request run in loop.

  • collection.bru:
script:pre-request {
  bru.setVar("i", 0);
}

script:post-response {
  console.log(`Collection post response i=${bru.getVar("i")}`);
  bru.setVar("i", bru.getVar("i") + 1);
  
}
  • check.bru:
meta {
  name: check
  type: http
  seq: 2
}

get {
  url: http://localhost:8000/check
  body: none
  auth: none
}

script:post-response {
  console.log(`Request post response i=${bru.getVar("i")}`);
  await bru.sleep(1000);
  bru.setNextRequest("check");
  
}

Output when run in CLI:

Running Folder Recursively

check (404 NOT FOUND) - 53 ms
Request post response i=0
Collection post response i=0
check (404 NOT FOUND) - 7 ms
Request post response i=0
Collection post response i=0
Collection post response i=1
check (404 NOT FOUND) - 5 ms
Request post response i=0
Collection post response i=0
Collection post response i=1
Collection post response i=2
check (404 NOT FOUND) - 11 ms
Request post response i=0
Collection post response i=0
Collection post response i=1
Collection post response i=2
Collection post response i=3

Console message "Collection post response i=..." should not appear multiple times per request repetition.

Screenshots/Live demo link

Run with desktop app:

image

@amaulave amaulave added the bug Something isn't working label Dec 31, 2024
@ganesh-bruno ganesh-bruno self-assigned this Jan 2, 2025
@ganesh-bruno
Copy link
Collaborator

Hi @amaulave,

Thank you for creating this issue.

I’ve been able to reproduce it on my end, and we're working on it.

@Tikamar
Copy link

Tikamar commented Jan 7, 2025

Hello,

I've the very same issue using setNextRequest() into a Post Response script of a request on any Collection where there is some Pre Request script, for any version of the Bruno CLI greater than 1.35.0.
So it's OK downgrading to 1.35.0 as a temporary workaround:
npm install -g @usebruno/[email protected]

The symptom is a message saying "Identifier yourVariableName has already been declared" where yourVariableName is the 1st variable declared into your Pre Request Script at collection level.

Hope it helps! 😉

@ganesh-bruno
Copy link
Collaborator

Hey @amaulave,

Could you please test this feature on the latest Bruno version and let us know if the issue still persists?
Download from here : https://www.usebruno.com/downloads

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working module-collection-runner
Projects
None yet
Development

No branches or pull requests

4 participants