Skip to content

Commit

Permalink
chore: Fix failing tests
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Miranda <[email protected]>
  • Loading branch information
alberto-miranda committed Dec 20, 2024
1 parent eaa985e commit 43f8bba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.seqera.tower.plugin

import com.google.common.cache.Cache
import com.google.common.cache.CacheBuilder
import com.google.common.util.concurrent.UncheckedExecutionException
import com.google.gson.Gson
import com.google.gson.JsonSyntaxException
import dev.failsafe.Failsafe
Expand Down Expand Up @@ -136,19 +137,22 @@ class TowerFusionEnv implements FusionEnv {
version: version
)

final key = '${product}-${version}'
def resp = tokenCache.get(
key,
() -> sendRequest(req)
) as LicenseTokenResponse

if( resp.expirationDate.before(new Date()) ) {
log.debug "Cached token already expired; refreshing"
resp = sendRequest(req)
tokenCache.put(key, resp)
try {
final key = '${product}-${version}'
def resp = tokenCache.get(
key,
() -> sendRequest(req)
) as LicenseTokenResponse

if( resp.expirationDate.before(new Date()) ) {
log.debug "Cached token already expired; refreshing"
resp = sendRequest(req)
tokenCache.put(key, resp)
}
return resp.signedToken
} catch (UncheckedExecutionException e) {
throw e.getCause()
}

return resp.signedToken
}

/**************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.seqera.tower.plugin

import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock
import groovy.json.JsonOutput
import io.seqera.tower.plugin.exception.UnauthorizedException
import nextflow.Global
import nextflow.Session
Expand All @@ -11,6 +12,8 @@ import nextflow.fusion.FusionConfig
import spock.lang.Shared
import spock.lang.Specification

import java.time.temporal.ChronoUnit

/**
* Test cases for the TowerFusionEnv class.
*
Expand Down Expand Up @@ -256,14 +259,16 @@ class TowerFusionEnvTest extends Specification {
def provider = new TowerFusionEnv()

and: 'a mock endpoint returning a valid token'
final now = new Date().toInstant()
final expirationDate = JsonOutput.toJson(Date.from(now.plus(1, ChronoUnit.DAYS)))
wireMockServer.stubFor(
WireMock.post(WireMock.urlEqualTo("/license/token/"))
.withHeader('Authorization', WireMock.equalTo('Bearer abc123'))
.willReturn(
WireMock.aResponse()
.withStatus(200)
.withHeader('Content-Type', 'application/json')
.withBody('{"signedToken":"xyz789"}')
.withBody('{"signedToken":"xyz789", "expirationDate":' + expirationDate + '}')
)
)

Expand Down

0 comments on commit 43f8bba

Please sign in to comment.