vlsi commented on code in PR #6891:
URL: https://github.com/apache/jmeter/pull/6891#discussion_r4738874507
##########
src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestCacheManagerBase.java:
##########
@@ -59,8 +62,9 @@ protected String makeDate(Instant d) {
}
public void setUp() throws Exception {
- this.cacheManager = new CacheManager();
- this.currentTimeInGMT = makeDate(Instant.now());
+ this.clock = new MutableClock(Instant.now());
Review Comment:
**F1 minor** The fake clock starts at `Instant.now()`, so no test fails if
the expiry computation reads `System.currentTimeMillis()` instead of the clock.
Problem: The fake time and the system time agree to within milliseconds when
an entry is cached, so the tests check only the read in `entryStillValid`
(CacheManager.java:628) against the clock. The reads that compute the expiry
date (CacheManager.java:408, 426, 441, 445) can go back to the system clock
with the suite still green, although the description says CacheManager reads
the time from the clock.
```java
// CacheManager.java:408 and :426 changed back to the system clock:
return new Date(System.currentTimeMillis() + maxAgeInSecs * 1000);
return new Date(System.currentTimeMillis() + Math.round(
// ./gradlew --quiet -Prelease -PenableErrorprone=false
:src:protocol:http:test --tests
'org.apache.jmeter.protocol.http.control.TestCacheManager*'
// current: 82 completed, 0 failed
// expected: the tests that cache an entry with max-age or Last-Modified fail
```
Proposed solution: start the clock at a fixed instant. Lines 441 and 445
stay unexecuted after the suggestion; a case each (a response with
Last-Modified and no Date header, and one with an unparseable Date header, each
valid just before one year after the clock time and expired just after) would
check them, or the description can name those paths as untested.
```suggestion
this.clock = new
MutableClock(Instant.parse("2001-02-03T04:05:06.789Z"));
```
##########
src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/control/TestCacheManagerHeaderSource.java:
##########
@@ -61,6 +64,23 @@ public void tearDown() throws Exception {
super.tearDown();
}
+ @Test
+ @SuppressWarnings("deprecation")
+ public void testCloneAndProxyKeepClock() throws Exception {
+ this.cacheManager.setUseExpires(true);
+ this.cacheManager = (CacheManager) this.cacheManager.clone();
+ this.cacheManager.testIterationStart(null);
+ setCacheControl("max-age=1");
+ long start = clock.millis();
+ cacheResult(sampleResultOK);
+ CacheManager proxy = this.cacheManager.createCacheManagerProxy();
+ assertTrue(this.cacheManager.inCache(url), "Clone should find valid
entry");
+ assertTrue(proxy.inCache(url), "Proxy should find valid entry");
+ clock.setMillis(start + 2010);
+ assertFalse(this.cacheManager.inCache(url), "Clone should find expired
entry");
+ assertFalse(proxy.inCache(url), "Proxy should find expired entry");
Review Comment:
**F2 nit** `testCloneAndProxyKeepClock` makes the proxy from the clone and
checks both in one chain of assertions, so a clone that loses the clock hides
whether the proxy keeps it.
Problem: `clone()` and `createCacheManagerProxy()` copy the clock in two
separate places (CacheManager.java:114 and :734); when both lose it, the report
names only the clone.
Proposed solution: Split it into a test for the clone and a test for a proxy
made from the original cache manager, each with its valid-then-expired pair.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]