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.

Question: Parallel integration tests

See original GitHub issue

Hello,

my app is a simple (ASP.NET Core) Web Api. I’m using the AuditApiAttribute to decorate endpoints that should log audit events. This works totally fine and as expected.

Sadly I cannot test these logs in my integration/unit test due to the nature of Audit.NET: A singleton implementation. I tried to look into the implementation details of AuditApiAttribute but I saw it uses simple constructor calls (new X()) instead of dependency injection. I currently don’t see how I can replace the default audit scope creation on a per request/app basis.

Most of my integration/unit tests are run in parallel so the global data provider cannot be used. If I use it it is replaced in every test setup which causes the audit logs to go to any collection (it’s random basically). I do want my tests to be isolated and do not want all of them to write to a big collection.

I saw talks about this issue in the past (#315) but I’m not really sure how it was resolved. I don’t want to write my own api attribute if possible. I also do not want to use the middleware if possible because I want a whitelist approach. Not a blacklist approach 😃

Any ideas?

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
thepirat000commented, Dec 21, 2022

This fix was included in version 20.1.3, please upgrade your references and re-test

https://github.com/thepirat000/Audit.NET/blob/master/src/Audit.WebApi/README.md#output

1reaction
MeikelLPcommented, Dec 21, 2022

Thank you! I think this a big quality improvement overall. Thanks for your work and response time 😃

My tests all turned green now. No more randomness 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to run integration tests in parallel (Spring boot)?
So, we create objects of test classes, and using the Stream API, then call the parallel() method (but here I do not control...
Read more >
What is Parallel Testing and How Does it Work? - Semaphore CI
Our starting definition may look deceptively simple: we say we're performing parallel testing when two or more tests are run simultaneously.
Read more >
Allow integration tests against the DB to be run in parallel
When doing integration tests that involve DB calls some issues may arise if the tests are run in parallel. Example: In a test...
Read more >
Running Parallel Functional Tests | by Amit Michaely
This process will allow you to run all of the test groups in parallel, while, within a group, the tests run sequentially. Nevertheless,...
Read more >
How to execute tests parallel?
Create a different CI-Jobs and split the execution of the tests. Or split them by integration and Junits. I don't know how much...
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