Skip to content

Conversation

ryanofsky
Copy link
Contributor

@ryanofsky ryanofsky commented Feb 18, 2022

Avoid using a test fixture in getarg_tests for better readability. Change was implemented by kiminuo and posted #24306 (comment)

@DrahtBot DrahtBot added the Tests label Feb 18, 2022
SetupArgs(local_args, {okaylog_bool, okaylog_negbool, okaylog, dontlog});
ResetArgs(local_args, "-okaylog-bool -nookaylog-negbool -okaylog=public -dontlog=private");

LogInstance().StartLogging();
Copy link
Member

Choose a reason for hiding this comment

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

CI fails sequentially. Maybe due to this?

Copy link
Contributor

Choose a reason for hiding this comment

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

This line turns off the logger buffering feature: https://github.com/ryanofsky/bitcoin/blob/55059269fe7379912b315a80f3a1a17b33a3e23d/src/logging.cpp#L68

so that https://github.com/ryanofsky/bitcoin/blob/55059269fe7379912b315a80f3a1a17b33a3e23d/src/logging.cpp#L267 is false and the logger callbacks are called

https://github.com/ryanofsky/bitcoin/blob/55059269fe7379912b315a80f3a1a17b33a3e23d/src/logging.cpp#L278-L280

I have tried to run locally src/test/test_bitcoin --log_level=all --run_test=getarg_tests and it passes. However, src/test/test_bitcoin does not pass for me so you are right and it can be reasonably reproduced. Also as one may expect variable s is empty (https://github.com/ryanofsky/bitcoin/blob/55059269fe7379912b315a80f3a1a17b33a3e23d/src/test/getarg_tests.cpp#L307).

Copy link
Contributor

Choose a reason for hiding this comment

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

So the error is because of this line https://github.com/ryanofsky/bitcoin/blob/55059269fe7379912b315a80f3a1a17b33a3e23d/src/logging.cpp#L53 as m_print_to_file is true sometimes so the callback is not called.

Copy link
Contributor

Choose a reason for hiding this comment

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

kiminuo@1ca557e might actually fix the issue but I'm not sure what you would say about the change. Anyway, I don't really know about a different solution so either that or closing #24375.

This uncovers that working with static variables is hard :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #24375 (comment)

I wasn't really sure how to reproduce this but now I tried switching to the BasicTestingSetup fixture to see if that fixes it

Copy link
Contributor

Choose a reason for hiding this comment

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

I used src/test/test_bitcoin --run_test=getarg_tests,fs_tests to reproduce the issue.

Copy link
Contributor

@kiminuo kiminuo Feb 18, 2022

Choose a reason for hiding this comment

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

My understanding is that Logger instance is shared between tests. So then fs_tests and getarg_tests interfere with each other because the BasicTestingSetup fixture sets a file name, then getarg_tests/logargs and its LogInstance().StartLogging(); does not turn off buffering of log messages and then the callback in logargs is not actually called.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ryanofsky Do you feel like switching to BasicTestingSetup is a good enough result for now or do you feel like it would be actually fruitful to remove the dependency on BasicTestingSetup?

I think it is reasonable to reserve the later for a future PR as it seems it requires more changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ryanofsky Do you feel like switching to BasicTestingSetup is a good enough result for now or do you feel like it would be actually fruitful to remove the dependency on BasicTestingSetup?

I don't think there's a problem with depending on BasicTestingSetup here, but maybe I am coming at this from different perspective. I think global variables are almost always a problem, but test fixtures are only sometimes a problem (#22155 (comment) was a place where I previously objected to using test fixtures unnecessarily).

Copy link
Contributor Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

SetupArgs(local_args, {okaylog_bool, okaylog_negbool, okaylog, dontlog});
ResetArgs(local_args, "-okaylog-bool -nookaylog-negbool -okaylog=public -dontlog=private");

LogInstance().StartLogging();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #24375 (comment)

I wasn't really sure how to reproduce this but now I tried switching to the BasicTestingSetup fixture to see if that fixes it

@DrahtBot
Copy link
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #24306 (util: Make ArgsManager::GetPathArg more widely usable by ryanofsky)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@kiminuo
Copy link
Contributor

kiminuo commented Feb 28, 2022

ACK 5d7f225

@maflcko maflcko merged commit 08bcfa2 into bitcoin:master Mar 2, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Mar 2, 2022
…est file.

5d7f225 Do not use `LocalTestingSetup` in getarg_tests test file. (Kiminuo)

Pull request description:

  Avoid using a test fixture in getarg_tests for better readability. Change was implemented by _kiminuo_ and posted bitcoin#24306 (comment)

ACKs for top commit:
  kiminuo:
    ACK 5d7f225

Tree-SHA512: 0fd98622010e6923e91c66447a1d0861bf344a65d86a313dff7d428c089b1740a25f699327f6ed4c163255f270bcbd4f7be962bb551862214f9b9e395d40df04
@bitcoin bitcoin locked and limited conversation to collaborators Mar 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants