Fetch of authorization token 64/7964/1
authorPatrikBuhr <patrik.buhr@est.tech>
Mon, 21 Mar 2022 08:25:27 +0000 (09:25 +0100)
committerPatrikBuhr <patrik.buhr@est.tech>
Mon, 21 Mar 2022 08:26:19 +0000 (09:26 +0100)
Trying to fix unstable unittest. Timing issue.

Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Issue-ID: NONRTRIC-735
Change-Id: I73869638e0c2ef1d5f7bd627eeb2de44dd53a0e5

auth-token-fetch/main_test.go

index 1b0a87e..c575614 100644 (file)
@@ -68,6 +68,7 @@ func TestFetchAndStoreToken(t *testing.T) {
        configuration.AuthTokenOutputFileName = "/tmp/authToken" + fmt.Sprint(time.Now().UnixNano())
        configuration.ClientId = "testClientId"
        configuration.ClientSecret = "testClientSecret"
+       configuration.RefreshMarginSeconds = 1
        context := NewContext(configuration)
 
        t.Cleanup(func() {
@@ -75,7 +76,7 @@ func TestFetchAndStoreToken(t *testing.T) {
        })
 
        accessToken := "Access_token" + fmt.Sprint(time.Now().UnixNano())
-       token := JwtToken{Access_token: accessToken, Expires_in: 10, Token_type: "Token_type"}
+       token := JwtToken{Access_token: accessToken, Expires_in: 7, Token_type: "Token_type"}
 
        wg := sync.WaitGroup{}
        wg.Add(2) // Get token two times
@@ -83,7 +84,7 @@ func TestFetchAndStoreToken(t *testing.T) {
 
        go periodicRefreshIwtToken(clientMock, context)
 
-       if waitTimeout(&wg, 7*time.Second) {
+       if waitTimeout(&wg, 12*time.Second) {
                t.Error("Not all calls to server were made")
                t.Fail()
        }