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

Some tests failing depending on timezone #4446

Closed
sxhinzvc opened this issue Jul 11, 2023 · 1 comment
Closed

Some tests failing depending on timezone #4446

sxhinzvc opened this issue Jul 11, 2023 · 1 comment
Assignees
Labels
type: task A general task

Comments

@sxhinzvc
Copy link
Contributor

When running the build, the following tests are failing due to date mismatch, based on the timezone.

MappingMongoConverterUnitTests#projectShouldReadSimpleInterfaceProjection
MappingMongoConverterUnitTests#projectShouldReadSimpleDtoProjection
AbstractEncryptionTestBase#encryptAndDecryptJavaTime

The tests are asserting against LocalDate objects in my timezone, which is UTC-5.

For MappingMongoConverterUnitTests#projectShouldReadSimpleInterfaceProjection:

org.opentest4j.AssertionFailedError: 
expected: 1999-12-01 (java.time.LocalDate)
 but was: 1999-11-30 (java.time.LocalDate)
@christophstrobl
Copy link
Member

christophstrobl commented Jul 12, 2023

Good catch - the testsetup is using UTC to define the source date. This is different to what the default Jsr310Converters.LocalDateToDateConverter does when writing a LocalDateInstance leading to the offset.

There's 2 options.

Use the LocalDateToDateConverter to create the source data.

org.bson.Document source = new org.bson.Document("birthDate",
	LocalDateToDateConverter.INSTANCE.convert(LocalDate.of(1999, 12, 1)))
	.append("foo", "Walter");

or stick to the UTC date conversion and set up the converter differently to use native java.time codecs.

configureConverterWithNativeJavaTimeCodec();

org.bson.Document source = new org.bson.Document("birthDate",
	Date.from(LocalDate.of(1999, 12, 1).atStartOfDay().toInstant(ZoneOffset.UTC))).append("foo", "Walter");

For the encryption tests we should use the UTC based variant via MongoConverterConfigurationAdapter#useNativeDriverJavaTimeCodecs().

@sxhinzvc sxhinzvc assigned sxhinzvc and unassigned christophstrobl Jul 12, 2023
christophstrobl pushed a commit that referenced this issue Jul 17, 2023
@christophstrobl christophstrobl added this to the 4.1.3 (2023.0.3) milestone Jul 17, 2023
@christophstrobl christophstrobl added type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: task A general task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants