Skip to content

Cleanup tables after each test#48

Merged
bbuchalter merged 1 commit into
masterfrom
cleanup_tables_for_each_test
Aug 27, 2018
Merged

Cleanup tables after each test#48
bbuchalter merged 1 commit into
masterfrom
cleanup_tables_for_each_test

Conversation

@bbuchalter

@bbuchalter bbuchalter commented Aug 27, 2018

Copy link
Copy Markdown

Closes #46.

This improves test isolation while also setting the stage to address
#47 by shortening the timestamps
in "lhma" tables. Without this cleanup, and without the precision of those
timestamps, tests were failing reporting duplicate table names.

Tophat instructions

dev clone lhm
dev down
dev up
dev test
./dbdeployer/sandboxes/rsandbox_5_7_22/m

See no tables are left after test suite is run.

master [localhost] {msandbox} ((none)) > SELECT table_name FROM information_schema.tables WHERE table_schema = 'test';
Empty set (0.00 sec)

Comment thread spec/integration/integration_helper.rb Outdated
cleanup_connection = new_mysql_connection
results = cleanup_connection.query("SELECT table_name FROM information_schema.tables WHERE table_schema = '#{$db_name}';")
table_names_for_cleanup = results.map { |row| "#{$db_name}." + row.values.first }
cleanup_connection.query("DROP TABLE #{table_names_for_cleanup.join(', ')};") if table_names_for_cleanup.length > 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

DROP TABLE IF EXISTS is always the way to go.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added.

@jordanwheeler

Copy link
Copy Markdown

i'm a little surprised this doesn't break any existing tests that relied on state leaking 😛

i suppose this beats adding a teardown to each test file like i would have done.

@bbuchalter bbuchalter force-pushed the cleanup_tables_for_each_test branch from ee8eb05 to 2fcb5a1 Compare August 27, 2018 18:27
Closes #46

This improves test isolation while also setting the stage to address
#47 by shortening the timestamps
in "lhma" tables. Without this cleanup, and without the precision of those
timestamps, tests were failing reporting duplicate table names.
@bbuchalter bbuchalter force-pushed the cleanup_tables_for_each_test branch from 2fcb5a1 to fad26f8 Compare August 27, 2018 18:27
@bbuchalter bbuchalter merged commit 671e82b into master Aug 27, 2018
@bbuchalter bbuchalter deleted the cleanup_tables_for_each_test branch August 27, 2018 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants