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

Incrementing an environment variable appears to have the environment file cached #1373

Closed
carlMosettig opened this issue Oct 11, 2023 · 4 comments
Labels
bug Something isn't working Priority Implement this asap

Comments

@carlMosettig
Copy link

carlMosettig commented Oct 11, 2023

Describe the bug
Incrementing a variable within an environment file does not take effect until the request completes

To Reproduce
Assuming an environment variable in place 'incrementCount' set with a value of 0.

Create a new get request, add a new post execution code element that will loop the request 20 times, for example

let incrementCount = tc.getVar('incrementCount') || 0

while( incrementCount < 20)
{
      // acting as if i didnt get the desired response so would like to retry
      tc.runRequest(<this request id>)
      incrementCount = incrementCount + 1
      tc.setVar( 'incrementCount', incrementCount)
      console.log(incrementCount)
}

Expected behavior
incrementCount should be incrementing and the console log should read similar to
1
2
3
4

**actual behaviour **

behaves like incoming environment is cached, console outputs

0
0
0
0
0

acts as if the final write to the environment isnt done until the request and code behind ends.

Platform:

  • OS: macos
  • vscode version: 1.82.3
  • extension version: v2.13.0 - (2023-10-08)

tried free and trial

@carlMosettig carlMosettig added the bug Something isn't working label Oct 11, 2023
@rangav
Copy link
Collaborator

rangav commented Oct 11, 2023

Hi @carlMosettig

Thanks for reporting the bug, Will fix it asap.

@rangav
Copy link
Collaborator

rangav commented Oct 12, 2023

This bug is fixed now, please update to v2.13.5

See all features released
https://github.com/rangav/thunder-client-support/releases/tag/v2.13.5

Please test and let me know your feedback.

@rangav rangav closed this as completed Oct 12, 2023
@rangav
Copy link
Collaborator

rangav commented Oct 12, 2023

Also I think you should use if condition instead of while because when you call runRequest it is doing the loop already.

@rangav
Copy link
Collaborator

rangav commented Oct 13, 2023

Also, you should rearrange the code

  • change while to if condition
  • move runRequest at the bottom of the if condition, otherwise the next part of code is not reached, as you are calling runRequest which starts to process same request again.
let incrementCount = tc.getVar('incrementCount') || 0

if(incrementCount < 20)
{
      incrementCount = incrementCount + 1
      tc.setVar( 'incrementCount', incrementCount)
      console.log(incrementCount)
     // acting as if i didnt get the desired response so would like to retry
      await tc.runRequest(<this request id>) // <<--------------
}

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

No branches or pull requests

2 participants