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

Need for-loop to work in init context #950

Closed
kkeranen opened this issue Mar 13, 2019 · 3 comments
Closed

Need for-loop to work in init context #950

kkeranen opened this issue Mar 13, 2019 · 3 comments

Comments

@kkeranen
Copy link

kkeranen commented Mar 13, 2019

I'm initializing dozens (if not hundreds) of custom metrics (which have to be initialized in init context). Because there are so many custom metrics, I'm trying using this kind of code with nested for-loops (called in init context):

function initAllMetrics() {    
    for (var kilosOfNodes = 1; kilosOfNodes <= MaxKilosOfNodes; kilosOfNodes *= 2) {

        initMetric("APIMethod1-" + kilosOfNodes.toString() + "k");
        initMetric("APIMethod2-" + kilosOfNodes.toString() + "k");
        
        for (var links = 100; links <= 6400; kilosOfNodes *= 2) {
            initMetric("APIMethod3-" + links.toString() + "links-" + kilosOfNodes.toString() + "k");
            initMetric("APIMethod4-" + links.toString() + "links-" + kilosOfNodes.toString() + "k");
            initMetric("APIMethod5-" + links.toString() + "links-" + kilosOfNodes.toString() + "k");
        }
    }
}

However, the for-loop seems to be the only thing in this code not working in the init context.

The reason for so many custom metrics is stress testing of API, which takes some time to build up. So, during building up tests are run in different phases, and for each phase there are dozen or so tests with different parameters. From all the metrics we finally build up a 2D result report table, each cell showing median response time.

@na--
Copy link
Member

na-- commented Mar 13, 2019

for loops should work in the init context. I think the problem in your case is that you don't increment links in the inner loop, rather you increase kilosOfNodes, leading to an infinite loop... copy-paste issues... 😄

@kkeranen
Copy link
Author

Right. There was also another problem: MaxKilosOfNodes was defined after calling initAllMetrics. Now it works, but debugging this was difficult because console.log doesn't seem to work in init context.

@na--
Copy link
Member

na-- commented Mar 13, 2019

Yeah, I've also been bitten by the lack of logging in the init context, debugging stuff by throwing exceptions is not fun at all... Created a new issue about that, since it's going to be somewhat complicated to implement properly, mostly due to the k6 architecture: #951

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants