Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Log exceptions in tests to stderr #10657

Closed
wants to merge 3 commits into from

Conversation

DMRobertson
Copy link
Contributor

This makes it easy to see errors in background processes when you're
writing unit tests. Otherwise, you have to know/remember to look at the
test logs in _trial_temp.

David Robertson added 2 commits August 19, 2021 13:06
This makes it easy to see errors in background processes when you're
writing unit tests. Otherwise, you have to know/remember to look at the
test logs in `_trial_temp`.
@DMRobertson DMRobertson requested a review from a team August 19, 2021 12:12
@@ -35,7 +36,8 @@ def emit(self, record):
def setup_logging():
"""Configure the python logging appropriately for the tests.

(Logs will end up in _trial_temp.)
Logs will end up in _trial_temp. Exceptions are additionally
Copy link
Member

Choose a reason for hiding this comment

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

Not everything logged at logger.error is an exception! s/exceptions/errors/.

Likewise in the changelog, and the name of the handler.

handler.addFilter(LoggingContextFilter())
root_logger.addHandler(handler)
to_twisted_handler.setFormatter(formatter)
to_twisted_handler.addFilter(LoggingContextFilter())
Copy link
Member

Choose a reason for hiding this comment

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

I think this is redundant, as of #8051. (If it's not redundant, we need to do it for the other handler too.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright. I propose to test if this is redundant by

  • removing filter here
  • changing LoggingContextFilter to have some obvious side effect
  • trigger the new log-to-stderr behaviour, and look for the side effect

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Appears to be needed. Otherwise the call to debug in synapse/metrics/init.py:596 will fail because the record doesn't have a "request" field.

@richvdh
Copy link
Member

richvdh commented Aug 19, 2021

I'm a bit concerned that this makes the test output hard to parse - there's actually quite a lot of stuff logged at ERROR which is expected in the tests, and this makes it look like things are failing when they're not.

Might be worth getting opinions from the rest of the team, in the room?

@richvdh
Copy link
Member

richvdh commented Aug 19, 2021

(on the other hand, possibly a bunch of those things logged at ERROR shouldn't be...)

@DMRobertson
Copy link
Contributor Author

Don't think anyone was super keen on this, so I'll close this down.

Maybe something simpler would suffice. (If a test fails, print out "check homeserver.log in _trial_temp" in bright yellow)

@DMRobertson
Copy link
Contributor Author

DMRobertson commented Sep 3, 2021

Argh. Just lost about an hour to this again.

Can we do better? I'm guessing somewhere high up we catch any remaining uncaught exceptions and logger.exception them. Can we stop that during test runs so that they bubble up immediately?

If the concern is "but some tests are supposed to cause exceptions", in the past I've used pytest.raises to allow (and inspect!) that behaviour.

@richvdh
Copy link
Member

richvdh commented Sep 6, 2021

uncaught exceptions will cause a test to fail.

@richvdh
Copy link
Member

richvdh commented Sep 6, 2021

(I think the problem is that the exceptions being logged are caught)

It would be instructive to see the sorts of errors that you are seeing being logged that would have been useful to make a test fail. Then we can see where it is being caught, and whether it would make sense to stop catching it during tests.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants