mathpaquette / IQFeed.CSharpApiClient

IQFeed.CSharpApiClient is fastest and the most well-designed C# DTN IQFeed socket API connector available
MIT License
120 stars 43 forks source link

Lookup rate limiter test is flaky #108

Closed mrut2pac closed 3 years ago

mrut2pac commented 3 years ago

The below operations need to be atomic:

requests.Add(requestsCount);
Interlocked.Exchange(ref requestsCount, 0);

Otherwise we may get the requestsCount incremented in between the lines and resetting to 0 may lose some of the requests.

The quick fix could be look like:

var requestsCountCopy = requestsCount;
requests.Add(requestsCountCopy);
Interlocked.Add(ref requestsCount, -requestsCountCopy);

Something like this, IMHO, should remove the test flakiness.

mathpaquette commented 3 years ago

Okay good. I'm about to create a new PR to manage another issue we have.