-
Notifications
You must be signed in to change notification settings - Fork 11
add secondary address cache #159
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
Conversation
A few comments
I've made all of the above changes in the branch; retained the current functional test and added a couple of basic unit tests, but you will need to add some more unit tests to cover the various combinations of currently-un-cached, currently-cached, verifying that the cache expiry time is correct, checking that the cache is attempted to be refreshed if getAddress is called after the cached entry has expired etc. To make this a bit easier I've added the scaffolding needed for mocking the SecondaryAddressFinder using the mocktail package |
… its dependency (the real secondary address finder) injectable so can easily write unit tests to cover all the behaviour, added some unit tests which inject a mock object as the SecondaryAddressFinder dependency
@gkc say i lookup @ alice from bob's client. But after this I never lookup @ alice again. In this case, @ alice should be removed from cache at some point..right? |
I don't think there's any need to remove @ alice from the cache; I don't see any downside to leaving it there except for a few bytes of memory. |
print(cache.getCacheExpiryTime(atSign)); | ||
print(approxExpiry); | ||
expect(cache.getCacheExpiryTime(atSign), isNotNull); | ||
expect((approxExpiry - cache.getCacheExpiryTime(atSign)!) < 100, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@@ -101,5 +105,11 @@ void main() async { | |||
expect(cache.getCacheExpiryTime(atSign), isNotNull); | |||
expect((approxExpiry - cache.getCacheExpiryTime(atSign)!) < 100, true); | |||
}); | |||
|
|||
test('test update cache for atsign which is not yet cached', () async { | |||
var atSign = 'notCachedAtSign1'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add an assertion that the atsign is not cached before calling cache.getAddress
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
SecondaryAddress addr = SecondaryAddress(secondaryHost, secondaryPort); | ||
_map[atSign] = SecondaryAddressCacheEntry(addr, DateTime.now().add(cacheFor).millisecondsSinceEpoch); | ||
} on Exception catch (e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have been wondering more about this. One of the problems we have is when we throw an exception. So I think we should just return the cached value (even if it is stale, it's better than throwing an exception) - and perhaps for visibility, add another field to the CacheEntry like 'lookupException' which would be 'most recent cache refresh fail reason'; would be set when we catch an exception, would be cleared when a lookup succeeds.
- What I did
- How I did it
- How to verify it
- Description for the changelog