Skip to content

Commit

Permalink
Fix missing wave response (#5547) [ci fast]
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso authored Nov 27, 2024
1 parent 09ccd29 commit ee25217
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
17 changes: 12 additions & 5 deletions plugins/nf-wave/src/main/io/seqera/wave/plugin/WaveClient.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import java.time.Duration
import java.time.Instant
import java.time.OffsetDateTime
import java.time.temporal.ChronoUnit
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import java.util.function.Predicate
Expand Down Expand Up @@ -104,7 +105,9 @@ class WaveClient {

final private String endpoint

private Cache<String, Handle> cache
private Cache<String, SubmitContainerTokenResponse> cache

private Map<String,Handle> responses = new ConcurrentHashMap<>()

private Session session

Expand Down Expand Up @@ -135,7 +138,7 @@ class WaveClient {
this.packer = new Packer().withPreserveTimestamp(config.preserveFileTimestamp())
this.waveRegistry = new URI(endpoint).getAuthority()
// create cache
cache = CacheBuilder<String, Handle>
this.cache = CacheBuilder<String, Handle>
.newBuilder()
.expireAfterWrite(config.tokensCacheMaxDuration().toSeconds(), TimeUnit.SECONDS)
.build()
Expand Down Expand Up @@ -572,8 +575,12 @@ class WaveClient {
final key = assets.fingerprint()
log.trace "Wave fingerprint: $key; assets: $assets"
// get from cache or submit a new request
final handle = cache.get(key, () -> new Handle(sendRequest(assets),Instant.now()) )
return new ContainerInfo(assets.containerImage, handle.response.targetImage, key)
final resp = cache.get(key, () -> {
final ret = sendRequest(assets);
responses.put(key,new Handle(ret,Instant.now()));
return ret
})
return new ContainerInfo(assets.containerImage, resp.targetImage, key)
}
catch ( UncheckedExecutionException e ) {
throw e.cause
Expand Down Expand Up @@ -633,7 +640,7 @@ class WaveClient {
}

boolean isContainerReady(String key) {
final handle = cache.getIfPresent(key)
final handle = responses.get(key)
if( !handle )
throw new IllegalStateException("Unable to find any container with key: $key")
final resp = handle.response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import java.nio.file.attribute.FileTime
import java.time.Duration
import java.time.Instant

import com.google.common.cache.Cache
import com.sun.net.httpserver.HttpExchange
import com.sun.net.httpserver.HttpHandler
import com.sun.net.httpserver.HttpServer
Expand Down Expand Up @@ -1303,18 +1302,18 @@ class WaveClientTest extends Specification {
def 'should validate isContainerReady' () {
given:
def sess = Mock(Session) {getConfig() >> [wave: [build:[maxDuration: '500ms']]] }
def cache = Mock(Cache)
def cache = Mock(Map)
and:
def resp = Mock(SubmitContainerTokenResponse)
def handle = new WaveClient.Handle(resp,Instant.now())
def wave = Spy(new WaveClient(session:sess, cache: cache))
def wave = Spy(new WaveClient(session:sess, responses: cache))
boolean ready

// container succeeded
when:
ready = wave.isContainerReady('xyz')
then:
cache.getIfPresent('xyz') >> handle
cache.get('xyz') >> handle
and:
resp.requestId >> '12345'
resp.succeeded >> true
Expand All @@ -1328,7 +1327,7 @@ class WaveClientTest extends Specification {
when:
ready = wave.isContainerReady('xyz')
then:
cache.getIfPresent('xyz') >> handle
cache.get('xyz') >> handle
and:
resp.requestId >> '12345'
resp.succeeded >> null
Expand All @@ -1342,7 +1341,7 @@ class WaveClientTest extends Specification {
when:
ready = wave.isContainerReady('xyz')
then:
cache.getIfPresent('xyz') >> handle
cache.get('xyz') >> handle
and:
resp.requestId >> '12345'
resp.succeeded >> false
Expand All @@ -1357,7 +1356,7 @@ class WaveClientTest extends Specification {
when:
ready = wave.isContainerReady('xyz')
then:
cache.getIfPresent('xyz') >> handle
cache.get('xyz') >> handle
and:
resp.buildId >> 'bd-5678'
resp.cached >> false
Expand All @@ -1371,7 +1370,7 @@ class WaveClientTest extends Specification {
when:
ready = wave.isContainerReady('xyz')
then:
cache.getIfPresent('xyz') >> handle
cache.get('xyz') >> handle
and:
resp.requestId >> null
resp.buildId >> 'bd-5678'
Expand All @@ -1386,7 +1385,7 @@ class WaveClientTest extends Specification {
when:
ready = wave.isContainerReady('xyz')
then:
cache.getIfPresent('xyz') >> handle
cache.get('xyz') >> handle
and:
resp.requestId >> null
resp.buildId >> 'bd-5678'
Expand Down

0 comments on commit ee25217

Please sign in to comment.