Improve reliability of ProposedGeneratedTests

This commit is contained in:
Sanne Grinovero 2021-11-24 16:14:39 +00:00 committed by Sanne Grinovero
parent 46857f456a
commit 25d8fda12c
1 changed files with 16 additions and 2 deletions

View File

@ -11,6 +11,7 @@ import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import org.hibernate.HibernateError;
import org.hibernate.dialect.SybaseASEDialect;
import org.hibernate.tuple.GenerationTiming;
@ -48,8 +49,8 @@ public class ProposedGeneratedTests {
created.name = "first";
// Precision is in milliseconds, so sleep a bit to ensure the TS changes
Thread.sleep( 10L );
//We need to wait a little to make sure the timestamps produced are different
waitALittle();
// then changing
final GeneratedInstantEntity merged = scope.fromTransaction( (session) -> {
@ -64,6 +65,9 @@ public class ProposedGeneratedTests {
assertThat( merged ).isNotNull();
//We need to wait a little to make sure the timestamps produced are different
waitALittle();
// lastly, make sure we can load it..
final GeneratedInstantEntity loaded = scope.fromTransaction( (session) -> {
return session.get( GeneratedInstantEntity.class, 1 );
@ -98,4 +102,14 @@ public class ProposedGeneratedTests {
this.name = name;
}
}
private static void waitALittle() {
try {
Thread.sleep( 10 );
}
catch (InterruptedException e) {
throw new HibernateError( "Unexpected wakeup from test sleep" );
}
}
}