-
Notifications
You must be signed in to change notification settings - Fork 5
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
Run tests against PostgreSQL, fix compatibility #170
Conversation
Codecov Report
@@ Coverage Diff @@
## development #170 +/- ##
===============================================
+ Coverage 90.01% 90.66% +0.65%
===============================================
Files 43 43
Lines 2633 2807 +174
===============================================
+ Hits 2370 2545 +175
+ Misses 263 262 -1
Continue to review full report at Codecov.
|
…onger try-and-error phase
@@ -21,8 +21,6 @@ pub async fn create_database(url: &str) -> Result<()> { | |||
Any::create_database(url).await?; | |||
} | |||
|
|||
Any::drop_database(url); |
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.
What was that? 😱
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 think it was never await
-ed, therefore it also never worked, but 😱
@@ -144,7 +144,7 @@ impl OperationStore<VerifiedOperation> for SqlStorage { | |||
.bind(name.to_owned()) | |||
.bind(value.field_type().to_string()) | |||
.bind(db_value) | |||
.bind(index.to_string()) | |||
.bind(index as i32) |
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.
👆 PostgreSQL was complaining that this column is actually a number (NUMERIC
).
COALESCE(document_view_id, 0) | ||
); | ||
-- @TODO: This fails using PostgreSQL | ||
-- CREATE UNIQUE INDEX ux_tasks ON tasks ( |
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.
👆 Upsi, this doesn't seem to work on PostgreSQL 😢
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.
Since the migrations fail all tests fail for PostgreSQL and MySQL currently
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.
Fixed now via:
CREATE UNIQUE INDEX ux_tasks ON tasks (
name,
COALESCE(document_id, '0'),
COALESCE(document_view_id, '0')
);
@@ -15,7 +15,7 @@ CREATE TABLE IF NOT EXISTS operation_fields_v1 ( | |||
operation_id TEXT NOT NULL, | |||
name TEXT NOT NULL, | |||
field_type TEXT NOT NULL, | |||
value BLOB NULL, | |||
value TEXT NULL, |
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.
👆 BLOB
is not known for PostgreSQL?
Small reportProblems of testing a databaseSo far this "somewhat" does what it promises: It runs the tests against a PostgreSQL and MySQL database. Problem is, that whenever a test panics it leaves the connection to the database alive, nothing gets disconnected afterwards 😢 Since we drop and re-create the database for every test this leads to ugly errors:
You can see it here for example: https://github.com/p2panda/aquadoggo/runs/7022667094?check_suite_focus=true The first test fails "correctly" and then all the others fail because of this lock. I couldn't find a way to disconnect from databases automatically when something fails, except of manually catching every error and doing it manually .. maybe you have an idea? Also, by testing a "real" database, we can't run the tests concurrently, we can assure this by adding I assume as soon as all tests are working again and we manually disconnect from the databases after every test it will go fine without any further changes. Our SQL queriesOtherwise, we get what we want, which is feedback on how it works with other databases and unluckily there are a few things failing. I've made some first fixes as commented in this PR, but there is more and I don't know if this is the place to fix that? I'd be fine doing it here. Here is an example of a failing test:
Where apparently .. and wow, what was that? #170 (comment) 😰 |
@@ -248,7 +248,7 @@ impl TestDatabaseRunner { | |||
pool.close().await; | |||
|
|||
// Panic here when test failed to propagate it further | |||
assert!(result.is_ok()); | |||
result.unwrap(); |
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 believe this will make #[should_panic]
work again
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.
Ah, DOH!!! Yeh, hopefully, why didn't I think of that...
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 tested it, it works again 👍
COALESCE(document_id, 0), | ||
COALESCE(document_view_id, 0) | ||
COALESCE(document_id, '0'), | ||
COALESCE(document_view_id, '0') |
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.
This needs to be a string
database: UNIQUE constraint failed: entries.author, entries.log_id, entries.seq_num" | ||
) | ||
let result = db.store.insert_entry(duplicate_doggo_entry).await; | ||
assert!(result.is_err()); |
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.
Returned error strings are different depending on the used database, so we need to just check via is_err
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'm really happy with this now.
Regarding the point I mentioned on the call earlier, I think seeing as we really are use rstest
everywhere then there's no need to add another option now.
} | ||
|
||
impl TestDatabaseRunner { | ||
pub fn with_db_teardown<F: AsyncTestFn + Send + Sync + 'static>(&self, test: F) { |
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.
A docstring here could be friendly for when you encounter this function in some test. Or maybe just a reference to another place to learn more.
// be reached even when the test panicked | ||
pool.close().await; | ||
|
||
// Panic here when test failed to propagate it further |
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 am not sure I understand this docstring. Propagate the error further? Wouldn't this get triggered exactly when an error is propagated further and not when it is not? If this enables #[should_panic]
that could also be nice to mention here for whoever edits this code next.
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.
Not sure if I understand your question, but I'll try to explain it from another angle: Panicks in tasks are not propagated further ("unwinded"), they just crash the task. To allow the test runner to understand that something happend we have to take the task handle, unwrap it to inform the "parent" about its failure.
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 function of this is to make the test fail when it should :-D
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 had two wishes for docstrings and added some myself, otherwise it's all good!
TestDatabaseRunner
which is now used in all tests to make sure the database gets disconnected after every succeeding or failing test. It changes our style of making tests slightly, but not too much:fn
is notasync
#[tokio::test]
attribute used, we build our own tokio runtimeTestDatabaseRunner::with_db_teardown
method which also gives you access to the underlyingTestDatabase
instancesqlx
by switching it totokio
(it was still set toasync_std
and probably forgotten after the switch)Closing: #31 and #98
📋 Checklist
CHANGELOG.md