Skip to content

Commit

Permalink
feat(objectionary#2746):added new tests in OptCachedTest and todo
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanich96 committed Dec 28, 2023
1 parent 9be0d32 commit e272471
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@
* Returns already optimized XML if it's found in the cache.
*
* @since 0.28.11
* @todo #2674:30min The function {@code OptCached.contains(final XML xml)}
* isn't work properly. This function compares caching and compilation times,
* which may lead to erroneous results. We need to fix this.
* @todo #2746:30min The tests
* {@link org.eolang.maven.optimization.OptCachedTest#returnsFromCacheCorrectProgram(Path path)}
* and
* {@link org.eolang.maven.optimization.OptCachedTest#returnsFromCacheCorrectProgram(Path path)}
* show that getting from cache don't work correctly.
* Need to fix file validation from cache: using checksum, but not time.
*/
public final class OptCached implements Optimization {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,44 @@ void returnsFromCacheIfXmlAlreadyInCache(@TempDir final Path tmp) throws IOExcep
);
}

@Disabled
@Test
void returnsFromCacheButTimesSaveAndExecuteDifferent(@TempDir final Path tmp)
throws IOException, InterruptedException {
final XML program = OptCachedTest.program(ZonedDateTime.now());
Thread.sleep(70_000);
OptCachedTest.save(tmp, program);
MatcherAssert.assertThat(
"We expected that the program will be returned from the cache",
new OptCached(
path -> {
throw new IllegalStateException("This code shouldn't be executed");
},
tmp
).apply(program),
Matchers.equalTo(program)
);
}

@Disabled
@Test
void returnsFromCacheCorrectProgram(@TempDir final Path tmp)
throws IOException, InterruptedException {
XML program = OptCachedTest.programWithSomethings(ZonedDateTime.now(), "first program");
OptCachedTest.save(tmp, program);
program = OptCachedTest.programWithSomethings(ZonedDateTime.now(), "second program");
MatcherAssert.assertThat(
"We expected that the correct program will be returned from the cache",
new OptCached(
path -> {
throw new IllegalStateException("This code shouldn't be executed");
},
tmp
).apply(program),
Matchers.equalTo(program)
);
}

@Test
void optimizesIfXmlIsAbsentInCache(@TempDir final Path tmp) {
final XML program = OptCachedTest.program();
Expand Down Expand Up @@ -158,4 +196,23 @@ private static XML program(final ZonedDateTime time) {
).xmlQuietly()
);
}

/**
* Generates EO program for tests with specified time and content.
* @param time Time.
* @param something String.
* @return XML representation of program.
*/
private static XML programWithSomethings(final ZonedDateTime time, final String something) {
return new XMLDocument(
new Xembler(
new Directives()
.add("program")
.attr("name", "main")
.attr("time", time.format(DateTimeFormatter.ISO_INSTANT))
.attr("something", something)
.up()
).xmlQuietly()
);
}
}

0 comments on commit e272471

Please sign in to comment.