RobThree / IdGen

Twitter Snowflake-alike ID generator for .Net
MIT License
1.19k stars 148 forks source link

Performance Tests #6

Closed mkrain closed 6 years ago

mkrain commented 6 years ago

This is more of a question than an issue. Looking at the unit tests I don't see any performance tests, is it possible to add some to validate that the number of generated ids do not collide, i.e. they are unique for a given time interval within the mask resolution?

RobThree commented 6 years ago

CreateId_Throws_OnSequenceOverflow tests specifically for overflow within the mask resolution within a single time interval.

You could test for other masks but that doesn't make much sense; you can't test every possible combination (within reason, and expecting the tests to run quickly); just as you also don't test the + operator for all combinations of operands. You test at the edge(s) of the limits (n-1, n, n+1) and that is what that test does. It generates a few ID's expecting no problems and then expects an overflow for the next ID generated.

What you may be looking over or missing is that we're using a MockTimeSource so we can advance (or revert) time as we wish. So there's no need to create a bunch of ID's hoping the time will elapse some specific interval. It makes testing (especially 'performance testing') much easier and reliable.

Suggestions for specific tests are welcome though.