question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Core: uniformRandomSwitch with 6 possibilities sometimes executes nothing

See original GitHub issue

Hi guys,

I think there is a bug in uniformRandomSwitch implementation - when you have i.e. 6 cases defined, sometimes no case is executed at all.

Steps to reproduce:

  1. Get fresh gatling-sbt-plugin-demo project (Gatling v3.0.3)
  2. Use below simulation:
class ComputerWorld extends Simulation {

  val computerDbScn = scenario("Uniform Random Switch Scenario")
    .forever() {
      exec(_.reset)

        .uniformRandomSwitch(
          exec(_.set("foo", 1)),
          exec(_.set("foo", 2)),
          exec(_.set("foo", 3)),
          exec(_.set("foo", 4)),
          exec(_.set("foo", 5)),
          exec(_.set("foo", 6))
        )

        .doIf("${foo.isUndefined()}") {
          exec(session => {
            println("++++++++++ FOO IS UNDEFINED ++++++++++")
            session
          })
        }
    }

  setUp(
    computerDbScn.inject(atOnceUsers(1))
      .protocols(http.baseUrl("http://computer-database.gatling.io"))
  )
}
  1. Execute simulation, i.e. sbt "gatling:testOnly *ComputerWorld"

Actual: There are many executions where variable foo is not defined after executing uniformRandomSwitch.

Expected: uniformRandomSwitch should make sure to always execute one of defined cases.

Cheers, Adam

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
slandellecommented, Mar 14, 2019

@aartajew As I said, I wasn’t satisfied with the existing implementation. New ones looks way better (and has unit tests…).

0reactions
aartajewcommented, Mar 14, 2019

I think there is a simpler solution, please see the comment below:

def uniformRandomSwitch(possibilities: ChainBuilder*): B = {
    require(possibilities.size >= 2, "uniformRandomSwitch() requires at least 2 possibilities")

    val possibility1 :: tailPossibilities = possibilities.toList
    val basePercentage = 100d / (tailPossibilities.size + 1) 
    // now round basePercentage to 2 decimals only, the rest is fine
    val firstPercentage = 100d - basePercentage * tailPossibilities.size

    val possibilitiesWithPercentage = (firstPercentage, possibility1) :: tailPossibilities.map((basePercentage, _))

    randomSwitch(possibilitiesWithPercentage, None)
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Scenario - Gatling
How to define scenarios that your virtual users will execute. Use exec to attach a chain or execute a request or a function....
Read more >
CONCEPTS IN RELIABLE AND OPTIMAL SYSTEMS DESIGNS
Sometimes this technique is referred to as energy minimization wherein the concept is ... evolution is searching a constantly changing set of possibilities....
Read more >
2014 - jmeter
Execution Phase: In this phase tests are executed and results are generated for the analysis phase. It is assumed that the setup phase...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found