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

Introduce DbTestClient which can be used to reset DB before the next test #28188

Closed
sberyozkin opened this issue Sep 25, 2022 · 5 comments
Closed
Labels
area/hibernate-orm Hibernate ORM area/testing kind/enhancement New feature or request

Comments

@sberyozkin
Copy link
Member

Description

I've started securing quarkus-quickstarts/hibernate-orm-panache-quickstart in devmode, with quarkus-oidc, and by adding @RolesAllowed to various endpoint methods. The tests delete one of the entities, so running them first as admin, and then as user does not work, because by the time the user is checked, one of the entities has gone.
In DevUI, there is a nice option to reset DB, clicking it reruns and SQL script used in the demo.

It would be good, in tests, to have something like

DbTestClient dbClient = new DbTestClient();
// before each test: dbClient.reset()

@Test 
public void testAsAdmin() {
}
@Test 
public void testAsUser() {
} 

Both tests will pass in any order and with each of them having side-effects. And the reset DB option would be available not only in Dev UI but also in tests

It would be similar to KeycloakTestClient which is initialized by DevServices for Keycloak with the added of Keycloak.

Implementation ideas

No response

@sberyozkin sberyozkin added the kind/enhancement New feature or request label Sep 25, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Sep 25, 2022

/cc @Sanne, @gsmet, @yrodiere

@sberyozkin sberyozkin changed the title Introduce DbTestClient which can be used to reset DB between the test Introduce DbTestClient which can be used to reset DB before the next test Sep 25, 2022
@yrodiere
Copy link
Member

Hey @sberyozkin, I think this duplicates #14240? #15198 seems related as well in some way.

Also, there was an attempt to solve this in the past, in #15827 , but it wasn't merged for some reason.

@sberyozkin
Copy link
Member Author

sberyozkin commented Sep 26, 2022

Hey @yrodiere Sorry, I haven't analyzed what has been done before in this area, and looks like, in #15827, it was assumed it was too complex to do right, with several alternatives considered.
I've no problems with closing this issue, but perhaps I can keep it open for a bit to have the discussion refreshed ? I saw in #15827 some concerns expressed, but it works well from DevUI, I believe it is of primary interest to tests depending on PostgreSQL and other containers launched by DB Dev Services so perhaps it can make sense to mirror this option in the tests...

@yrodiere
Copy link
Member

yrodiere commented Sep 26, 2022

No problem with restarting the discussion, but let's not duplicate it? I think it would be better to post your API suggestion to #14240, and to link any PR to that.

And yes, I think most agree that this feature has value; the disagreement was about execution. I think your solution of a (injected?) client that controls the reset probably solves most issues we had.

@sberyozkin
Copy link
Member Author

@yrodiere Sure, will do. Stuart had a nice test system enhancement, so I'll update #14240 and propose to fix it similarly to how it was done for KeycloakTestClient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM area/testing kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants