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

Race condition causes periodic failure to generate html report #3

Closed
jwtd opened this issue Jan 17, 2015 · 6 comments
Closed

Race condition causes periodic failure to generate html report #3

jwtd opened this issue Jan 17, 2015 · 6 comments
Labels

Comments

@jwtd
Copy link

jwtd commented Jan 17, 2015

I've setup grunt-api-benchmark to generate both the html and json versions of the benchmark results from the same config file.

    api_benchmark: {
      restApi: {
        options: {
          output: 'tests/benchmarks/'
        },
        files: {
          'api-benchmark.html': 'tests/acceptance/api-benchmark.json',
          'api-benchmark.json': 'tests/acceptance/api-benchmark.json'
        }
      }
    }

The task always creates the api-benchmark.json file, but sporadicly creates the api-benchmark.html file. When I say "sporadicly", I mean that I can run the task 5 times without changing anything, and a few of the times it will create the html file successfully, and a few times it won't.

I traced the issue to a fs.readFile call in api-benchmark. That call is asynchronous, and it seems to be creating a race condition with the grunt task's code.

When I change that line to...

var template = fs.readFileSync(path.join(__dirname, '../templates/report.html'), 'utf-8');

...the html version of the file gets created every single time without fail.

@matteofigus
Copy link
Owner

Good spot, thanks! Can you include here, just for reference, node version you are using, OS and module version (is it the latest one?)

I'll try to have a look later today.

Thanks
Matteo

@matteofigus
Copy link
Owner

Just published v0.1.1 - Can you try to upgrade an see if it is fixed? 👍

@jwtd
Copy link
Author

jwtd commented Jan 17, 2015

Node v0.10.35
grunt-api-benchmark v0.1.0

I updated to grunt-api-benchmark@0.1.1, but my task still intermittently fails to generate the html file. This is what I get...

jd$ grunt benchmark
Running "api_benchmark:restApi" (api_benchmark) task
Performing benchmarks for file: tests/acceptance/api-benchmark.json
REST api/simpleRoute x 1,265 ops/sec ±1.61% (1000 runs sampled)
REST api/secondaryRoute x 1,185 ops/sec ±2.19% (1000 runs sampled)
REST api/postRoute x 1,623 ops/sec ±1.72% (1000 runs sampled)
REST api/deleteRoute x 1,545 ops/sec ±1.64% (1000 runs sampled)
File "tests/benchmarks/api-benchmark.json" created.

Done, without errors.

@matteofigus
Copy link
Owner

Lol, my fault! Can you retry with 0.1.2? 👍

@jwtd
Copy link
Author

jwtd commented Jan 19, 2015

Both reports are being generated regularly. Seems to be working as expected now. Thanks!

@matteofigus
Copy link
Owner

yay :) closing this. Thanks for your help 👍

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

No branches or pull requests

2 participants