amoghrajesh commented on code in PR #77762:
URL: https://github.com/apache/airflow/pull/77762#discussion_r4748002569
##########
AGENTS.md:
##########
@@ -166,6 +166,7 @@ reported as such are described in "What is NOT considered a
security vulnerabili
- Use `spec`/`autospec` when mocking.
- Prefer `@mock.patch` decorators over `with mock.patch(...)` context managers
for patching. Use `conf_vars` (from `tests_common.test_utils.config`) for
Airflow config overrides — as a decorator when the value is fixed, as a context
manager when it varies via `@pytest.mark.parametrize` or is only known at run
time. In `async def` tests always use it as a context manager inside the body:
as a decorator it hides the coroutine from pytest-asyncio and the test fails.
- Use `time_machine` for time-dependent tests. Do not use `datetime.now()`
+- Do not assert on elapsed wall-clock time (`time.monotonic() - start < N`) or
release threads with `threading.Timer`: both flake on loaded CI runners.
Synchronise with `threading.Event` or `threading.Barrier` and assert order
instead, e.g. that an event is still unset when the call returns. Patch time
functions where the code under test looks them up
(`mock.patch("pkg.module.time.monotonic")`), never `time.monotonic` or
`time.sleep` globally, which also changes the clock for boto, moto and other
libraries.
Review Comment:
Handled in 8c3705fb6c2
##########
.github/instructions/code-review.instructions.md:
##########
@@ -40,6 +40,7 @@ Use these rules when reviewing pull requests to the Apache
Airflow repository.
- **Flag any `unittest.TestCase` subclass.** Use pytest patterns instead.
- **Flag any `mock.Mock()` or `mock.MagicMock()` without `spec` or
`autospec`.** Unspec'd mocks silently accept any attribute access, hiding real
bugs.
- **Flag any `time.sleep` or `datetime.now()` in tests.** Use `time_machine`
for time-dependent tests.
+- **Flag elapsed-time assertions and `threading.Timer` in tests.** Checks like
`time.monotonic() - start < 1` and threads released by timers flake on loaded
CI runners. Use `threading.Event` and assert order instead. Also flag global
`time.*` patches such as `mock.patch("time.monotonic")`; patch the name in the
module under test.
Review Comment:
Handled in 8c3705fb6c2
--
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]