Eason09053360 commented on code in PR #74364:
URL: https://github.com/apache/airflow/pull/74364#discussion_r4213848105
##########
airflow-core/tests/unit/models/test_revoked_token.py:
##########
@@ -97,7 +104,117 @@ def test_cleanup_skips_when_interval_not_passed(self):
):
RevokedToken.is_revoked("test-jti", session=mock_session)
- # session.execute should NOT be called
+ mock_session.scalars.assert_not_called()
+ mock_session.execute.assert_not_called()
+ finally:
+ RevokedToken._last_cleanup_time = original_last_cleanup
+
+ def test_cleanup_skipped_while_another_thread_is_cleaning(self):
+ """The interval bookkeeping is not thread safe, so only one pass may
run at a time."""
+ mock_session = MagicMock()
+ mock_session.scalar.return_value = False
+
+ original_last_cleanup = RevokedToken._last_cleanup_time
+ RevokedToken._cleanup_lock.acquire()
+ try:
+ RevokedToken._last_cleanup_time = 0.0
+ with (
+ patch("airflow.models.revoked_token.time.monotonic",
return_value=8000.0),
+ patch("airflow.models.revoked_token.conf.getint",
return_value=3600),
+ ):
+ assert RevokedToken.is_revoked("test-jti",
session=mock_session) is False
+
+ mock_session.scalars.assert_not_called()
mock_session.execute.assert_not_called()
+ # a skipped pass must not claim the interval either
+ assert RevokedToken._last_cleanup_time == 0.0
finally:
+ RevokedToken._cleanup_lock.release()
RevokedToken._last_cleanup_time = original_last_cleanup
+
+ def
test_failed_cleanup_rolls_back_so_the_revocation_read_still_works(self):
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]