Skip to content

Commit ee25217

Browse files
authored
Fix missing wave response (#5547) [ci fast]
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
1 parent 09ccd29 commit ee25217

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

plugins/nf-wave/src/main/io/seqera/wave/plugin/WaveClient.groovy

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import java.time.Duration
2727
import java.time.Instant
2828
import java.time.OffsetDateTime
2929
import java.time.temporal.ChronoUnit
30+
import java.util.concurrent.ConcurrentHashMap
3031
import java.util.concurrent.Executors
3132
import java.util.concurrent.TimeUnit
3233
import java.util.function.Predicate
@@ -104,7 +105,9 @@ class WaveClient {
104105

105106
final private String endpoint
106107

107-
private Cache<String, Handle> cache
108+
private Cache<String, SubmitContainerTokenResponse> cache
109+
110+
private Map<String,Handle> responses = new ConcurrentHashMap<>()
108111

109112
private Session session
110113

@@ -135,7 +138,7 @@ class WaveClient {
135138
this.packer = new Packer().withPreserveTimestamp(config.preserveFileTimestamp())
136139
this.waveRegistry = new URI(endpoint).getAuthority()
137140
// create cache
138-
cache = CacheBuilder<String, Handle>
141+
this.cache = CacheBuilder<String, Handle>
139142
.newBuilder()
140143
.expireAfterWrite(config.tokensCacheMaxDuration().toSeconds(), TimeUnit.SECONDS)
141144
.build()
@@ -572,8 +575,12 @@ class WaveClient {
572575
final key = assets.fingerprint()
573576
log.trace "Wave fingerprint: $key; assets: $assets"
574577
// get from cache or submit a new request
575-
final handle = cache.get(key, () -> new Handle(sendRequest(assets),Instant.now()) )
576-
return new ContainerInfo(assets.containerImage, handle.response.targetImage, key)
578+
final resp = cache.get(key, () -> {
579+
final ret = sendRequest(assets);
580+
responses.put(key,new Handle(ret,Instant.now()));
581+
return ret
582+
})
583+
return new ContainerInfo(assets.containerImage, resp.targetImage, key)
577584
}
578585
catch ( UncheckedExecutionException e ) {
579586
throw e.cause
@@ -633,7 +640,7 @@ class WaveClient {
633640
}
634641

635642
boolean isContainerReady(String key) {
636-
final handle = cache.getIfPresent(key)
643+
final handle = responses.get(key)
637644
if( !handle )
638645
throw new IllegalStateException("Unable to find any container with key: $key")
639646
final resp = handle.response

plugins/nf-wave/src/test/io/seqera/wave/plugin/WaveClientTest.groovy

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import java.nio.file.attribute.FileTime
2727
import java.time.Duration
2828
import java.time.Instant
2929

30-
import com.google.common.cache.Cache
3130
import com.sun.net.httpserver.HttpExchange
3231
import com.sun.net.httpserver.HttpHandler
3332
import com.sun.net.httpserver.HttpServer
@@ -1303,18 +1302,18 @@ class WaveClientTest extends Specification {
13031302
def 'should validate isContainerReady' () {
13041303
given:
13051304
def sess = Mock(Session) {getConfig() >> [wave: [build:[maxDuration: '500ms']]] }
1306-
def cache = Mock(Cache)
1305+
def cache = Mock(Map)
13071306
and:
13081307
def resp = Mock(SubmitContainerTokenResponse)
13091308
def handle = new WaveClient.Handle(resp,Instant.now())
1310-
def wave = Spy(new WaveClient(session:sess, cache: cache))
1309+
def wave = Spy(new WaveClient(session:sess, responses: cache))
13111310
boolean ready
13121311

13131312
// container succeeded
13141313
when:
13151314
ready = wave.isContainerReady('xyz')
13161315
then:
1317-
cache.getIfPresent('xyz') >> handle
1316+
cache.get('xyz') >> handle
13181317
and:
13191318
resp.requestId >> '12345'
13201319
resp.succeeded >> true
@@ -1328,7 +1327,7 @@ class WaveClientTest extends Specification {
13281327
when:
13291328
ready = wave.isContainerReady('xyz')
13301329
then:
1331-
cache.getIfPresent('xyz') >> handle
1330+
cache.get('xyz') >> handle
13321331
and:
13331332
resp.requestId >> '12345'
13341333
resp.succeeded >> null
@@ -1342,7 +1341,7 @@ class WaveClientTest extends Specification {
13421341
when:
13431342
ready = wave.isContainerReady('xyz')
13441343
then:
1345-
cache.getIfPresent('xyz') >> handle
1344+
cache.get('xyz') >> handle
13461345
and:
13471346
resp.requestId >> '12345'
13481347
resp.succeeded >> false
@@ -1357,7 +1356,7 @@ class WaveClientTest extends Specification {
13571356
when:
13581357
ready = wave.isContainerReady('xyz')
13591358
then:
1360-
cache.getIfPresent('xyz') >> handle
1359+
cache.get('xyz') >> handle
13611360
and:
13621361
resp.buildId >> 'bd-5678'
13631362
resp.cached >> false
@@ -1371,7 +1370,7 @@ class WaveClientTest extends Specification {
13711370
when:
13721371
ready = wave.isContainerReady('xyz')
13731372
then:
1374-
cache.getIfPresent('xyz') >> handle
1373+
cache.get('xyz') >> handle
13751374
and:
13761375
resp.requestId >> null
13771376
resp.buildId >> 'bd-5678'
@@ -1386,7 +1385,7 @@ class WaveClientTest extends Specification {
13861385
when:
13871386
ready = wave.isContainerReady('xyz')
13881387
then:
1389-
cache.getIfPresent('xyz') >> handle
1388+
cache.get('xyz') >> handle
13901389
and:
13911390
resp.requestId >> null
13921391
resp.buildId >> 'bd-5678'

0 commit comments

Comments
 (0)