Skip to content

Fix for non-deterministic failing tests #669

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

Merged
merged 3 commits into from
Feb 11, 2020
Merged

Fix for non-deterministic failing tests #669

merged 3 commits into from
Feb 11, 2020

Conversation

bart-degreed
Copy link
Contributor

Fixes #668.

I moved tests for NoEntityFrameworkTests into a different database, because two variants of TodoItem exist (where one is a subset of the other), causing tests to fail/succeed depending on their execution order.

A separate database is needed instead of schema, because context.Database.EnsureCreated() only checks for database existence and does not create additional tables when the database already exists.

Furthermore, I decided to remove fields from NoEntityFrameworkExample.Models.TodoItem that do not exist in the INSERT SQL statement in NoEntityFrameworkExample.Services.TodoItemService and because non-nullable CreatedDate causes insert to fail.

…ecause two variants of `TodoItem` exist (where one is a subset of the other), causing tests to fail/succeed depending on their execution order.

A separate database is needed instead of schema, because `context.Database.EnsureCreated()` only checks for database existence and does not create additional tables when the database already exists.

Furthermore, I decided to remove fields from `NoEntityFrameworkExample.Models.TodoItem` that do not exist in the INSERT SQL statement in `NoEntityFrameworkExample.Services.TodoItemService` and because non-nullable CreatedDate causes insert to fail.
@bart-degreed bart-degreed requested a review from maurei January 22, 2020 14:04
Bart Koelman added 2 commits February 5, 2020 13:04
This occured when working in the solution for a while, building and rebuilding one or more projects individually. What happened is that the appsettings.json from NoEntityFrameworkCoreExample project would overwrite the one from JsonApiDotNetCoreExample in the output folder of JsonApiDotNetCoreExample. Causing that project to reference the wrong database.

I solved this by removing the unneeded dependency between these projects and by relying on automatic copying of appsettings by the project system. I removed the copied appsettings.json files from the test projects, which end up in the output directory anyway (because they reference the *Example projects).
Copy link
Member

@maurei maurei left a comment

Choose a reason for hiding this comment

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

I'm unsure why I've never experienced indeterministic failing tests, but both the CI and my local tests still run fine with your update, so I have no objections. Thanks.

@maurei maurei merged commit 7015b21 into json-api-dotnet:master Feb 11, 2020
@bart-degreed bart-degreed deleted the tests-isolation branch February 11, 2020 21:57
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.

Failing unit tests
2 participants