From 3704dad923981f37628ec5904a84e96213f66f0d Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Wed, 5 Jan 2022 10:33:38 +0100 Subject: [PATCH] Add a wait to a test that uses a database generated timestamp --- .../temporals/MultipleGeneratedValuesTests.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/MultipleGeneratedValuesTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/MultipleGeneratedValuesTests.java index 56e6500ab5..64c505733b 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/MultipleGeneratedValuesTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/generated/temporals/MultipleGeneratedValuesTests.java @@ -11,6 +11,7 @@ import jakarta.persistence.Entity; import jakarta.persistence.Id; import jakarta.persistence.Table; +import org.hibernate.HibernateError; import org.hibernate.annotations.CurrentTimestamp; import org.hibernate.dialect.SybaseASEDialect; import org.hibernate.tuple.GenerationTiming; @@ -53,6 +54,9 @@ public class MultipleGeneratedValuesTests { created.name = "first"; + //We need to wait a little to make sure the timestamps produced are different + waitALittle(); + // then changing final GeneratedInstantEntity merged = scope.fromTransaction( (session) -> { return (GeneratedInstantEntity) session.merge( created ); @@ -70,6 +74,9 @@ public class MultipleGeneratedValuesTests { assertThat( merged.createdAt2 ).isEqualTo( created.createdAt2 ); assertThat( merged.updatedAt2 ).isNotEqualTo( created.updatedAt2 ); + //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 ); @@ -116,4 +123,13 @@ public class MultipleGeneratedValuesTests { this.name = name; } } + + private static void waitALittle() { + try { + Thread.sleep( 10 ); + } + catch (InterruptedException e) { + throw new HibernateError( "Unexpected wakeup from test sleep" ); + } + } }