-
Notifications
You must be signed in to change notification settings - Fork 266
PHPLIB-1177: SDAM logger example #1142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
/* Note: Do not assert output beyond the initial topology events, as it | ||
* may vary based on the test environment. PHPUnit's matching behavior | ||
* for "%A" also seems to differ slightly from run-tests.php, otherwise | ||
* we could assert the final topologyClosed event. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked through StringMatchesFormatDescription but couldn't figure out exactly why it differs from run-tests.php
. In my local testing, PHPUnit had trouble matching expected output after %A
, in contrast to the attached sdam_logger.phpt file (ignore the txt
extension, which was needed to appease GitHub's validation).
Relevant format in the phpt
test is:
--EXPECTF--
topologyOpening: %x was opened
topologyChanged: %x changed from Unknown to %s
%A
topologyChanged: %x changed from %s to %s
topologyClosed: %x was closed
===DONE===
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PHPUnit StringMatchesFormatDescription
splits line-by-line. So you cannot match several lines with a single %A
. This works on my machine:
$expectedOutput = <<<'OUTPUT'
topologyOpening: %x was opened
topologyChanged: %x changed from Unknown to %s
%A
%A
%A
%A
%A
%A
%A
%A
%A
%A
topologyChanged: %x changed from %s to %s
topologyClosed: %x was closed
OUTPUT;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PHPUnit StringMatchesFormatDescription splits line-by-line
Can you point me to where that happens? I know that StringMatchesFormatDescription has some logic to convert \r\n
(e.g. sebastianbergmann/phpunit@05db035), but it looks like it defers to preg_match
to handle multi-line strings.
A series of %A
patterns on their own line should be redundant, as that could otherwise be written with %S
(see: EXPECTF. And the regex conversion seemingly does attempt to handle newlines for %a
and %A
based on the conversion logic in regularExpressionForFormatDescription()
:
'%s' => '[^\r\n]+',
'%S' => '[^\r\n]*',
'%a' => '.+',
'%A' => '.*',
Asserting the number of newlines in the output is not portable, as that will vary based on the topology used to run the test. A 3-member replica set is going to log more lines than a 2-mongos sharded cluster or standalone server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been confused by the additionalFailureDescription
that does split lines.
|
||
/* Note: TopologyClosedEvent can only be observed for non-persistent clients. | ||
* Persistent clients are destroyed in GSHUTDOWN, long after any PHP objects | ||
* (including subscribers) are freed. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment lifted from topologyClosedEvent-001.phpt in PHPC, which also had a typo I fixed in mongodb/mongo-php-driver#1456.
/* Note: Do not assert output beyond the initial topology events, as it | ||
* may vary based on the test environment. PHPUnit's matching behavior | ||
* for "%A" also seems to differ slightly from run-tests.php, otherwise | ||
* we could assert the final topologyClosed event. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PHPUnit StringMatchesFormatDescription
splits line-by-line. So you cannot match several lines with a single %A
. This works on my machine:
$expectedOutput = <<<'OUTPUT'
topologyOpening: %x was opened
topologyChanged: %x changed from Unknown to %s
%A
%A
%A
%A
%A
%A
%A
%A
%A
%A
topologyChanged: %x changed from %s to %s
topologyClosed: %x was closed
OUTPUT;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. No objection to partial matches, as we're only testing the examples to make sure they run.
https://jira.mongodb.org/browse/PHPLIB-1177