Skip to content

Conversation

@MrCreosote
Copy link
Member

includes caching.

Also renames clients for less confusing stack traces

includes caching.

Also renames clients for less confusing stack traces
@codecov
Copy link

codecov bot commented Oct 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (93c4787) to head (92b00f8).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main        #8      +/-   ##
===========================================
+ Coverage   99.07%   100.00%   +0.92%     
===========================================
  Files           4         4              
  Lines         217       269      +52     
===========================================
+ Hits          215       269      +54     
+ Misses          2         0       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

raise ValueError("timer is required")
self._token_cache = LRUCache(maxsize=cache_max_size, timer=timer)
self._user_cache = LRUCache(maxsize=cache_max_size, timer=timer)
self._user_name_cache = LRUCache(maxsize=cache_max_size, timer=timer)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor thing, but it's slightly annoying to have usernames and user_name. Can we pick a way to refer to the names of users and stick to it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

if not tk: # minor optimization, don't get the token until it's needed
tk = await self.get_token(token)
# Usernames are permanent but can be disabled, so we expire based on time
# Don't cache non-existant names, could be created at any time and would

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

existent

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines 241 to 243
exists = u in res
to_return[u] = exists
if exists:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you just do

  to_return[u] = u in res
  if to_return[u]:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines +339 to +350
async def test_validate_usernames_noop(auth_users):
with KBaseAuthClient.create(AUTH_URL) as cli:
res1 = cli.validate_usernames(auth_users["user"])
res2 = cli.validate_usernames(auth_users["user"], " \t ")
async with await AsyncKBaseAuthClient.create(AUTH_URL) as cli:
res3 = await cli.validate_usernames(auth_users["user"])
res4 = await cli.validate_usernames(auth_users["user"], " ")

assert res1 == {}
assert res2 == {}
assert res3 == {}
assert res4 == {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a good candidate for parametrize

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since half the methods are sync and half are async I'm not really sure about that. If it was 4 operations that were all the same I'd agree


@pytest.mark.asyncio
async def test_get_token_basic_fail(auth_users):
async def test_get_token_fail(auth_users):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you able to generate sync tests from the async template in the same way that you have done the code itself? There's a lot of repetition -- doing things the async way and then doing them the sync way.

There are also places where you could parametrize the tests but haven't done so.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe? I thought about that but decided I'd rather make it blindingly obvious to future devs that they needed to test both the sync and async versions of the code by putting the tests side by side.

Also, from personal experience, maintaining both isn't that hard

Copy link

@ialarmedalien ialarmedalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not all that fussed about the various optimisations I mentioned being done NOW -- they are just worth bearing in mind, depending on how much more development is going to be done on this code.

@MrCreosote
Copy link
Member Author

I suspect that changes are going to be few and far between once the basics are done

@MrCreosote MrCreosote merged commit e9dd3a2 into main Oct 13, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants