1515
1616public class GitHubSanityCachedValueTest {
1717
18+ private static void alignToStartOfSecond () {
19+ while (Instant .now ().getNano () > 100_000_000 ) {
20+ Thread .yield ();
21+ }
22+ }
23+
1824 @ Test
1925 public void cachesWithinSameSecond () throws Exception {
2026 alignToStartOfSecond ();
@@ -35,28 +41,6 @@ public void cachesWithinSameSecond() throws Exception {
3541 assertThat (calls .get (), equalTo (1 ));
3642 }
3743
38- @ Test
39- public void refreshesAfterOneSecond () throws Exception {
40- GitHubSanityCachedValue <String > cachedValue = new GitHubSanityCachedValue <>();
41- AtomicInteger calls = new AtomicInteger ();
42-
43- String first = cachedValue .get (() -> {
44- calls .incrementAndGet ();
45- return "value" ;
46- });
47-
48- Thread .sleep (1100 );
49-
50- String second = cachedValue .get (() -> {
51- calls .incrementAndGet ();
52- return "value" ;
53- });
54-
55- assertThat (first , equalTo ("value" ));
56- assertThat (second , equalTo ("value" ));
57- assertThat (calls .get (), equalTo (2 ));
58- }
59-
6044 @ Test
6145 public void concurrentCallersOnlyRefreshOnce () throws Exception {
6246 alignToStartOfSecond ();
@@ -98,10 +82,25 @@ public void concurrentCallersOnlyRefreshOnce() throws Exception {
9882 }
9983 }
10084
101- private static void alignToStartOfSecond () {
102- while (Instant .now ().getNano () > 100_000_000 ) {
103- Thread .yield ();
104- }
85+ @ Test
86+ public void refreshesAfterOneSecond () throws Exception {
87+ GitHubSanityCachedValue <String > cachedValue = new GitHubSanityCachedValue <>();
88+ AtomicInteger calls = new AtomicInteger ();
89+
90+ String first = cachedValue .get (() -> {
91+ calls .incrementAndGet ();
92+ return "value" ;
93+ });
94+
95+ Thread .sleep (1100 );
96+
97+ String second = cachedValue .get (() -> {
98+ calls .incrementAndGet ();
99+ return "value" ;
100+ });
101+
102+ assertThat (first , equalTo ("value" ));
103+ assertThat (second , equalTo ("value" ));
104+ assertThat (calls .get (), equalTo (2 ));
105105 }
106106}
107-
0 commit comments