Skip to content

Commit

Permalink
Improve reliability of ProposedGeneratedTests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanne committed Dec 1, 2021
1 parent 46857f4 commit 25d8fda
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import jakarta.persistence.Id;
import jakarta.persistence.Table;

import org.hibernate.HibernateError;
import org.hibernate.dialect.SybaseASEDialect;
import org.hibernate.tuple.GenerationTiming;

Expand Down Expand Up @@ -48,8 +49,8 @@ public void test(SessionFactoryScope scope) throws InterruptedException {

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) -> {
Expand All @@ -64,6 +65,9 @@ public void test(SessionFactoryScope scope) throws InterruptedException {

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 );
Expand Down Expand Up @@ -98,4 +102,14 @@ public GeneratedInstantEntity(Integer id, String name) {
this.name = name;
}
}

private static void waitALittle() {
try {
Thread.sleep( 10 );
}
catch (InterruptedException e) {
throw new HibernateError( "Unexpected wakeup from test sleep" );
}
}

}

0 comments on commit 25d8fda

Please sign in to comment.