Skip to content
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

Test improvements #174

Merged
merged 10 commits into from
Nov 7, 2018
Merged

Test improvements #174

merged 10 commits into from
Nov 7, 2018

Conversation

benlangfeld
Copy link
Collaborator

@benlangfeld benlangfeld commented Nov 7, 2018

Some of this was extracted from the work on Redis Streams support. I think it's worthwhile even before that happens.

Other parts generally improve the structure of the test suite (duplication of tests and conditional test definition rather than execution), it's communication of intent (a simpler forking spec) and its stability (avoiding regular failure in the forking spec on Redis).

We were testing from recovery from a full flush, but it is also possible for a backlog to expire while message ID counters persist.
This test was introduced in discourse@9c16e7e . Its purpose does not appear to be to assert that the forked process has a subscription (since no code is present to ensure that delivery ocurrs to both processes), nor does the order of publication or delivery appear to be important in this spec. All we're really interested in asserting here is that publications before a fork, from the forked process, and from the original process after the fork ocurrs, all get published and delivered. This change expresses that case much more simply.

Prior to this change, this test would fail on Redis approximately 20% of the time. With this change, it did not fail at all in 30 executions.
These specs were all being applied only to specific backends. Several of them are (functionally) the same, and do not need to be maintained separately. Those tests which do not apply to all backends are now clearly indicated by calling `test_only [some backend(s)]`, forming a todo list for building feature parity.
@benlangfeld
Copy link
Collaborator Author

@SamSaffron If you are amenable to these changes, I would prefer that they be merged first and #175 subsequently require conflict resolution than the other way around. Thanks for your time!

The previous tests simply asserted that the backend-specific mechanism for expiring backlogs on Redis was set up, but not that it actually worked. The test could not, then, be exercised on other backends, whose implementations of backlog expiry do not have the same behaviour as those of the Redis backend.

These tests now assert the behaviour of the Redis backend, but do not invoke any private APIs specific to Redis, and can thus be applied to other backend implementations.
This allows the tests to assert that the preferred behaviour is for expiry to be automatic at the correct time, and that this ocurrs on compatible backends. Conversely, the tests assert that backends which require publication-triggered expiry do not auto-expire; if they gain such functionality in the future, the tests would have to be updated to reflect this, allowing us to work towards eliminating this divergence in behaviour from the tests.

@bus.pub_redis.flushdb
@bus.reset!
Copy link
Member

Choose a reason for hiding this comment

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

I much prefer reset methods, way cleaner


@bus.global_backlog.length.must_equal 1

sleep 1.25 # Should now be at time =~ 1.25s. Our backlog should have expired by now.
Copy link
Member

Choose a reason for hiding this comment

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

sleeps in tests make me uneasy, is there any other option here. even if we give a special "rush" method o back ends or something.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not aware of a way to wind Redis' clock forward. The point of this is to actually exercise Redis' expiry rather than fake it in message_bus.

@SamSaffron
Copy link
Member

Overall I am fine with the changes it improves the test suite a lot 👍

@benlangfeld
Copy link
Collaborator Author

@SamSaffron If you're happy, I'm ready for this to be merged. I have another PR coming up to improve feature-parity.

@SamSaffron
Copy link
Member

Sure lets go for it! Thanks Ben

@SamSaffron SamSaffron merged commit eb4613c into discourse:master Nov 7, 2018
@benlangfeld benlangfeld deleted the test-improvements branch November 7, 2018 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants