-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added lifetime for the Resources in Label definition (#39)
With lifetime timeout we can be sure the application resource will not be executed forever if something bad happened and based on this timeout fish node will be able to do some heuristics on how much time left till provisioning the next resource (#38). The duration is set in standard golang format as string "1h2m3s", if it's empty or 0 - the default from fish config will be used. And if it's negative (like "-1s") then the resource should exist until user say so by deallocating it. This change really helps with clouds where we certainly don't need to left the resources for long time.
- Loading branch information
Showing
5 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/** | ||
* Copyright 2021 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tests | ||
|
||
import ( | ||
"crypto/tls" | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
"github.com/steinfletcher/apitest" | ||
|
||
"github.com/adobe/aquarium-fish/lib/openapi/types" | ||
) | ||
|
||
// Checks the Application is getting deallocated by timeout | ||
func Test_label_lifetime_timeout(t *testing.T) { | ||
t.Parallel() | ||
afi := RunAquariumFish(t, `--- | ||
node_name: node-1 | ||
node_location: test_loc | ||
api_address: 127.0.0.1:0 | ||
drivers: | ||
- name: test`) | ||
|
||
t.Cleanup(func() { | ||
afi.Cleanup() | ||
}) | ||
|
||
defer func() { | ||
if r := recover(); r != nil { | ||
fmt.Println("Recovered in f", r) | ||
} | ||
}() | ||
|
||
tr := &http.Transport{ | ||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | ||
} | ||
cli := &http.Client{ | ||
Timeout: time.Second * 5, | ||
Transport: tr, | ||
} | ||
|
||
var label types.Label | ||
t.Run("Create Label", func(t *testing.T) { | ||
apitest.New(). | ||
EnableNetworking(cli). | ||
Post(afi.ApiAddress("api/v1/label/")). | ||
JSON(`{"name":"test-label", "version":1, "definitions": [ | ||
{"driver":"test","resources":{"cpu":1,"ram":2,"lifetime":"15s"}} | ||
]}`). | ||
BasicAuth("admin", afi.AdminToken()). | ||
Expect(t). | ||
Status(http.StatusOK). | ||
End(). | ||
JSON(&label) | ||
|
||
if label.UID == uuid.Nil { | ||
t.Fatalf("Label UID is incorrect: %v", label.UID) | ||
} | ||
}) | ||
|
||
var app types.Application | ||
t.Run("Create Application", func(t *testing.T) { | ||
apitest.New(). | ||
EnableNetworking(cli). | ||
Post(afi.ApiAddress("api/v1/application/")). | ||
JSON(`{"label_UID":"`+label.UID.String()+`"}`). | ||
BasicAuth("admin", afi.AdminToken()). | ||
Expect(t). | ||
Status(http.StatusOK). | ||
End(). | ||
JSON(&app) | ||
|
||
if app.UID == uuid.Nil { | ||
t.Fatalf("Application UID is incorrect: %v", app.UID) | ||
} | ||
}) | ||
|
||
var app_state types.ApplicationState | ||
t.Run("Application should get ALLOCATED in 10 sec", func(t *testing.T) { | ||
Retry(&Timer{Timeout: 10 * time.Second, Wait: 1 * time.Second}, t, func(r *R) { | ||
apitest.New(). | ||
EnableNetworking(cli). | ||
Get(afi.ApiAddress("api/v1/application/"+app.UID.String()+"/state")). | ||
BasicAuth("admin", afi.AdminToken()). | ||
Expect(r). | ||
Status(http.StatusOK). | ||
End(). | ||
JSON(&app_state) | ||
|
||
if app_state.Status != types.ApplicationStatusALLOCATED { | ||
r.Fatalf("Application Status is incorrect: %v", app_state.Status) | ||
} | ||
}) | ||
}) | ||
|
||
time.Sleep(10 * time.Second) | ||
|
||
t.Run("Application should be still ALLOCATED in 10 sec", func(t *testing.T) { | ||
apitest.New(). | ||
EnableNetworking(cli). | ||
Get(afi.ApiAddress("api/v1/application/"+app.UID.String()+"/state")). | ||
BasicAuth("admin", afi.AdminToken()). | ||
Expect(t). | ||
Status(http.StatusOK). | ||
End(). | ||
JSON(&app_state) | ||
|
||
if app_state.Status != types.ApplicationStatusALLOCATED { | ||
t.Fatalf("Application Status is incorrect: %v", app_state.Status) | ||
} | ||
}) | ||
|
||
t.Run("Application should get DEALLOCATED in 5 sec", func(t *testing.T) { | ||
Retry(&Timer{Timeout: 5 * time.Second, Wait: 1 * time.Second}, t, func(r *R) { | ||
apitest.New(). | ||
EnableNetworking(cli). | ||
Get(afi.ApiAddress("api/v1/application/"+app.UID.String()+"/state")). | ||
BasicAuth("admin", afi.AdminToken()). | ||
Expect(r). | ||
Status(http.StatusOK). | ||
End(). | ||
JSON(&app_state) | ||
|
||
if app_state.Status != types.ApplicationStatusDEALLOCATED { | ||
r.Fatalf("Application Status is incorrect: %v", app_state.Status) | ||
} | ||
}) | ||
}) | ||
} |