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

Run tests against PostgreSQL, fix compatibility #170

Merged
merged 63 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
6b42328
Make database url configurable for tests
adzialocha Jun 22, 2022
5a6ccd4
Add github action for postgres, probably this is the beginning of a l…
adzialocha Jun 22, 2022
63b0df2
Add --command
adzialocha Jun 22, 2022
2a0c0df
Add MySQL, try using services
adzialocha Jun 22, 2022
51908c5
Enable logging
adzialocha Jun 22, 2022
21e41b6
Try different logging
adzialocha Jun 22, 2022
b5276a8
Remove that fancy fluff
adzialocha Jun 22, 2022
25567a1
Fix comment
adzialocha Jun 22, 2022
bad9952
Do not reset
adzialocha Jun 22, 2022
3dada54
Who did that typo?
adzialocha Jun 22, 2022
d21efa5
Reset databases again
adzialocha Jun 22, 2022
e22f704
Correct database env var for postgres container
adzialocha Jun 22, 2022
a598bfe
What was that
adzialocha Jun 22, 2022
a0f86e1
Reduce parallelization
adzialocha Jun 22, 2022
8c5199c
Do not use BLOB
adzialocha Jun 22, 2022
0935387
Make sure to disconnect when migration failed
adzialocha Jun 22, 2022
1aad8f0
Set mysql database again
adzialocha Jun 22, 2022
413cfbb
Correctly run tests serially
adzialocha Jun 22, 2022
590dbd3
WIP
adzialocha Jun 23, 2022
1ca7976
Fix column type
adzialocha Jun 23, 2022
05d2ad0
Clean up
adzialocha Jun 23, 2022
620f34b
Add missing trait again
adzialocha Jun 23, 2022
4236230
Bring back failing UNIQUE constraint
adzialocha Jun 23, 2022
f34b4e7
Merge branch 'development' into postgres-ci
adzialocha Jun 23, 2022
3d4acc2
Make previous_operations in OperationRow an Option
sandreae Jun 23, 2022
971cf99
Fix COALESCE type from int to text
adzialocha Jun 23, 2022
7894fd9
Make previous_operation an Option in OperationFieldsJoinedRow
sandreae Jun 23, 2022
275e19b
Update parse_operation_rows to account for None value previous_operat…
sandreae Jun 23, 2022
ae6a6c4
Don't check for exact db error strings
sandreae Jun 23, 2022
c2b657f
Missing await
sandreae Jun 23, 2022
e77ee40
Typo
sandreae Jun 23, 2022
4459eff
WIP massive test refactor making sure they get unwinded
adzialocha Jun 23, 2022
50e7168
Enable all features for the testing runtime
adzialocha Jun 23, 2022
2abfd81
Fix ownership for tests with many cases and borrowed values
adzialocha Jun 23, 2022
06ac905
Don't use rstest shoul_panic macro
sandreae Jun 23, 2022
79637c9
Make list_index INTEGER(255)
sandreae Jun 23, 2022
db0cccc
Revert list_index type change
sandreae Jun 23, 2022
89f0e2c
Make columns Option in OperationFieldRow
sandreae Jun 23, 2022
ba3a7ff
Don't check for specific error message strings
sandreae Jun 23, 2022
38bf7f8
Cast strings to numerics in get_paginated_log_entries()
sandreae Jun 23, 2022
1884016
Use ON CONFLICT to avoid task duplicates
sandreae Jun 23, 2022
d97e8b9
Use COALESCE to compare nullable strings
sandreae Jun 23, 2022
3980942
Use test runner in all mutation tests
sandreae Jun 23, 2022
7ab5a45
Revert removal of empty store in publish_entry test
sandreae Jun 24, 2022
f1cb76d
Refactor test which used two dbs
sandreae Jun 24, 2022
c3ba146
Use test runner in query tests
sandreae Jun 24, 2022
eb762f2
Use test runner for http service test
sandreae Jun 24, 2022
12a1028
Try different env var names for mariadb container
adzialocha Jun 24, 2022
2cde8b9
Try changing port configuration for mariadb container
adzialocha Jun 24, 2022
213709b
Try using container label as hostname
adzialocha Jun 24, 2022
df1d9b9
Roll back port changes
adzialocha Jun 24, 2022
89efbd7
Expose port properly
adzialocha Jun 24, 2022
ef08996
Remove MySQL support, fix async runtime of sqlx
adzialocha Jun 24, 2022
65130de
Add entry to CHANGELOG.md
adzialocha Jun 24, 2022
c51434f
Give null values the same representation as index
adzialocha Jun 24, 2022
d2129dd
Make fields in other rows also optional
adzialocha Jun 24, 2022
7c1275c
Last tests using old database utilities
adzialocha Jun 24, 2022
818139d
Clean up
adzialocha Jun 24, 2022
6778ba4
Remove unnecessary comments, just unwrap test result
adzialocha Jun 24, 2022
0c0fbcc
Make linters happy
adzialocha Jun 24, 2022
e7fd225
Improve formatting of long case tests
adzialocha Jun 24, 2022
5369d26
Edit comments
cafca Jun 27, 2022
cbad270
Add some more comments
adzialocha Jun 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 99 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,103 @@ jobs:
with:
command: test
args: --manifest-path ${{ env.cargo_manifest }}
# Ensure debug output is also tested
env:
# Ensure debug output is also tested
RUST_LOG: debug

rust-test-postgres:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:latest
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: aquadoggo-development
ports:
# Maps TCP port 5432 on service container to the host
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Restore from cargo cache
uses: actions/cache@v3
with:
path: ${{ env.cache_path }}
key: ${{ runner.os }}-test-${{ hashFiles('**/Cargo.lock') }}

- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
args: >-
--manifest-path ${{ env.cargo_manifest }}
-- --test-threads 1
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/aquadoggo-development

rust-test-mariadb:
runs-on: ubuntu-latest

services:
mariadb:
image: mariadb:latest
ports:
# Maps TCP port 3306 on service container to the host
- 3306:3306
env:
MYSQL_USER: panda
MYSQL_PASSWORD: panda
MYSQL_DATABASE: aquadoggo-development
MYSQL_ROOT_PASSWORD: root
options: >-
--health-cmd="mysqladmin ping"
--health-interval=5s
--health-timeout=2s
--health-retries=3

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Restore from cargo cache
uses: actions/cache@v3
with:
path: ${{ env.cache_path }}
key: ${{ runner.os }}-test-${{ hashFiles('**/Cargo.lock') }}

- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
args: >-
--manifest-path ${{ env.cargo_manifest }}
-- --test-threads 1
env:
DATABASE_URL: mysql://panda:panda@localhost:3306/aquadoggo-development

rust-check:
runs-on: ubuntu-latest

Expand Down Expand Up @@ -151,9 +244,12 @@ jobs:
uses: actions-rs/tarpaulin@v0.1
with:
# Force cleaning via `--force-clean` flag to prevent buggy code coverage
args: --manifest-path ${{ env.cargo_manifest }} --locked --force-clean
# Ensure debug output is also tested
args: >-
--manifest-path ${{ env.cargo_manifest }}
--locked
--force-clean
env:
# Ensure debug output is also tested
RUST_LOG: debug

- name: Upload to codecov.io
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion aquadoggo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ deadqueue = { version = "0.2.2", default-features = false, features = [
] }
directories = "3.0.2"
envy = "0.4.2"
futures = "0.3.21"
graphql_client = "0.10"
hex = "0.4.3"
lipmaa-link = "0.2.2"
Expand Down Expand Up @@ -58,11 +59,11 @@ tower-http = { version = "0.2.4", default-features = false, features = [
"cors",
] }
triggered = "0.1.2"
futures = "0.3.21"

[dev-dependencies]
hyper = "0.14.17"
http = "0.2.6"
once_cell = "1.12.0"
reqwest = { version = "0.11.9", default-features = false, features = [
"json",
"stream",
Expand Down
2 changes: 1 addition & 1 deletion aquadoggo/migrations/20220509090252_create-operations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Member Author

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?

list_index NUMERIC NOT NULL,
FOREIGN KEY(operation_id) REFERENCES operations_v1(operation_id)
);
Expand Down
11 changes: 6 additions & 5 deletions aquadoggo/migrations/20220617115933_create-tasks.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ CREATE TABLE IF NOT EXISTS tasks (
-- Create a unique index using `COALESCE`. A regular `UNIQUE` clause will
-- consider two rows that have at least one `null` value to always be distinct
-- but we want to check for equality including `null` values.
CREATE UNIQUE INDEX ux_tasks ON tasks (
name,
COALESCE(document_id, 0),
COALESCE(document_view_id, 0)
);
-- @TODO: This fails using PostgreSQL
-- CREATE UNIQUE INDEX ux_tasks ON tasks (
Copy link
Member Author

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 😢

Copy link
Member Author

@adzialocha adzialocha Jun 23, 2022

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

Copy link
Member Author

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')
);

-- name,
-- COALESCE(document_id, 0),
-- COALESCE(document_view_id, 0)
--);

-- Create an index because primary keys can not contain `null` columns.
CREATE INDEX idx_tasks ON tasks (name, document_id, document_view_id);
2 changes: 0 additions & 2 deletions aquadoggo/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ pub async fn create_database(url: &str) -> Result<()> {
Any::create_database(url).await?;
}

Any::drop_database(url);
Copy link
Member Author

Choose a reason for hiding this comment

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

What was that? 😱

Copy link
Member Author

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 😱


Ok(())
}

Expand Down
33 changes: 28 additions & 5 deletions aquadoggo/src/db/stores/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl DocumentStore for SqlStorage {
documents
LEFT JOIN document_view_fields
ON
documents.document_view_id = document_view_fields.document_view_id
documents.document_view_id = document_view_fields.document_view_id
LEFT JOIN operation_fields_v1
ON
document_view_fields.operation_id = operation_fields_v1.operation_id
Expand Down Expand Up @@ -268,7 +268,7 @@ impl DocumentStore for SqlStorage {
documents
LEFT JOIN document_view_fields
ON
documents.document_view_id = document_view_fields.document_view_id
documents.document_view_id = document_view_fields.document_view_id
LEFT JOIN operation_fields_v1
ON
document_view_fields.operation_id = operation_fields_v1.operation_id
Expand Down Expand Up @@ -419,6 +419,9 @@ mod tests {
assert!(retrieved_document_view.get(key).is_some());
assert_eq!(retrieved_document_view.get(key), document_view.get(key));
}

// Disconnect from database
db.close().await;
}

#[rstest]
Expand All @@ -438,7 +441,10 @@ mod tests {
.await
.unwrap();

assert!(view_does_not_exist.is_none())
assert!(view_does_not_exist.is_none());

// Disconnect from database
db.close().await;
adzialocha marked this conversation as resolved.
Show resolved Hide resolved
}

#[rstest]
Expand Down Expand Up @@ -496,6 +502,9 @@ mod tests {
};
assert_eq!(document_view.get("username").unwrap(), &expected_username);
}

// Disconnect from database
db.close().await;
}

#[rstest]
Expand All @@ -506,7 +515,6 @@ mod tests {
#[from(test_db)]
#[future]
db: TestSqlStore,

operation: Operation,
) {
let db = db.await;
Expand All @@ -527,6 +535,9 @@ mod tests {
result.unwrap_err().to_string(),
"A fatal error occured in DocumentStore: error returned from database: FOREIGN KEY constraint failed".to_string()
);

// Disconnect from database
db.close().await;
}

#[rstest]
Expand Down Expand Up @@ -575,6 +586,9 @@ mod tests {
assert!(document_view.get(key).is_some());
assert_eq!(document_view.get(key), expected_document_view.get(key));
}

// Disconnect from database
db.close().await;
}

#[rstest]
Expand Down Expand Up @@ -623,6 +637,9 @@ mod tests {
assert!(document_view.get(key).is_some());
assert_eq!(document_view.get(key), expected_document_view.get(key));
}

// Disconnect from database
db.close().await;
}

#[rstest]
Expand Down Expand Up @@ -651,6 +668,9 @@ mod tests {
let document_view = db.store.get_document_by_id(document.id()).await.unwrap();

assert!(document_view.is_none());

// Disconnect from database
db.close().await;
}

#[rstest]
Expand Down Expand Up @@ -678,6 +698,9 @@ mod tests {

let schema_documents = db.store.get_documents_by_schema(&schema_id).await.unwrap();

assert_eq!(schema_documents.len(), 2)
assert_eq!(schema_documents.len(), 2);

// Disconnect from database
db.close().await;
}
}
32 changes: 28 additions & 4 deletions aquadoggo/src/db/stores/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,10 @@ mod tests {
let doggo_entry = StorageEntry::new(&entry_encoded, &operation_encoded).unwrap();
let result = db.store.insert_entry(doggo_entry).await;

assert!(result.is_ok())
assert!(result.is_ok());

// Disconnect from database
db.close().await;
}

#[rstest]
Expand Down Expand Up @@ -485,7 +488,10 @@ mod tests {
result.unwrap_err().to_string(),
"Error occured during `EntryStorage` request in storage provider: error returned from \
database: UNIQUE constraint failed: entries.author, entries.log_id, entries.seq_num"
)
);

// Disconnect from database
db.close().await;
}

#[rstest]
Expand Down Expand Up @@ -515,6 +521,9 @@ mod tests {
.await
.unwrap();
assert_eq!(latest_entry.unwrap().seq_num(), SeqNum::new(20).unwrap());

// Disconnect from database
db.close().await;
}

#[rstest]
Expand Down Expand Up @@ -546,6 +555,9 @@ mod tests {
.await
.unwrap();
assert!(entries.len() == 40);

// Disconnect from database
db.close().await;
}

#[rstest]
Expand Down Expand Up @@ -591,7 +603,10 @@ mod tests {
.get_entry_at_seq_num(&author_not_in_db, &LogId::new(1), &seq_num_not_in_log)
.await
.unwrap();
assert!(entry.is_none())
assert!(entry.is_none());

// Disconnect from database
db.close().await;
}

#[rstest]
Expand Down Expand Up @@ -630,7 +645,10 @@ mod tests {
.get_entry_by_hash(&entry_hash_not_in_db)
.await
.unwrap();
assert!(entry.is_none())
assert!(entry.is_none());

// Disconnect from database
db.close().await;
}

#[rstest]
Expand Down Expand Up @@ -663,6 +681,9 @@ mod tests {
.unwrap();

assert_eq!(entries.len(), 10);

// Disconnect from database
db.close().await;
}

#[rstest]
Expand All @@ -689,5 +710,8 @@ mod tests {

assert!(!entries.is_empty());
assert_eq!(cert_pool_seq_nums, vec![19, 18, 17, 13, 4, 1]);

// Disconnect from database
db.close().await;
}
}
Loading