Skip to content

Commit e300c97

Browse files
committed
Fix tests using Java runtime (still experimental)
1 parent 3b70b3e commit e300c97

4 files changed

Lines changed: 25 additions & 49 deletions

File tree

internal/node/pool.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func dismissContainer(requiredMemoryMB int64) (bool, error) {
307307
}
308308
}
309309

310-
cleanup: // Phase 2: Cleanup
310+
cleanup: // Phase 2: Cleanup
311311
if cleanedMB >= requiredMemoryMB { // if we'd actually free enough memory we do it, otherwise there's no point
312312
for _, item := range containerToDismiss {
313313
if item.pool.removeContainerFromIdle(item.cont) {
@@ -380,6 +380,7 @@ func DeleteExpiredContainer() {
380380
// ShutdownWarmContainersFor destroys warm containers of a given function
381381
// Actual termination happens asynchronously.
382382
func ShutdownWarmContainersFor(f *function.Function) {
383+
log.Printf("Shutting down warm containers for %s", f.Name)
383384
LocalResources.Lock()
384385
defer LocalResources.Unlock()
385386

@@ -417,24 +418,18 @@ func ShutdownWarmContainersFor(f *function.Function) {
417418

418419
// ShutdownAllContainers destroys all container (usually on termination)
419420
func ShutdownAllContainers() {
421+
log.Printf("Shutting down ALL containers")
420422
LocalResources.Lock()
421423
defer LocalResources.Unlock()
422424

423-
for fun, pool := range LocalResources.containerPools {
424-
functionDescriptor, _ := function.GetFunction(fun)
425-
if functionDescriptor == nil {
426-
log.Printf("Could not find function, cannot shutdown containers: %s\n", fun)
427-
continue // should not happen
428-
}
429-
425+
for _, pool := range LocalResources.containerPools {
430426
for i, warmed := range pool.idle {
431427
log.Printf("Removing container with ID %s\n", warmed.ID)
432428

433429
err := container.Destroy(warmed.ID)
434430
if err != nil {
435431
log.Printf("Error while destroying container %s: %s", warmed.ID, err)
436432
}
437-
LocalResources.warmPoolUsedMem -= functionDescriptor.MemoryMB
438433

439434
// nil to help garbage collection
440435
pool.idle[i] = nil
@@ -452,14 +447,17 @@ func ShutdownAllContainers() {
452447
continue
453448
}
454449

455-
LocalResources.usedCPUs -= functionDescriptor.CPUDemand
456-
LocalResources.busyPoolUsedMem -= functionDescriptor.MemoryMB
457-
458450
pool.busy[i] = nil
459451
}
460452
// Reset the busy slice capacity
461453
pool.busy = pool.busy[:0]
462454
}
455+
456+
// NOTE: these values are not expected to be used again (we are shutting down the node)
457+
LocalResources.usedCPUs = 0
458+
LocalResources.busyPoolUsedMem = 0
459+
LocalResources.warmPoolUsedMem = 0
460+
463461
}
464462

465463
// WarmStatus foreach function returns the corresponding number of warm container available

internal/test/api_test.go

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,7 @@ func TestContainerPool(t *testing.T) {
3232
createApiIfNotExistsTest(t, fn, HOST, PORT)
3333
}
3434

35-
// creating java function
36-
javaFn, err := InitializeJavaFunction("hello-java", "com.test.HelloFunction", function.NewSignature().
37-
AddInput("name", function.Text{}).
38-
AddOutput("greeting", function.Text{}).
39-
Build())
40-
utils.AssertNil(t, err)
41-
createApiIfNotExistsTest(t, javaFn, HOST, PORT)
42-
43-
// executing all functions
35+
// executing function
4436
channel := make(chan error)
4537
const n = 3
4638
for i := 0; i < n; i++ {
@@ -54,26 +46,17 @@ func TestContainerPool(t *testing.T) {
5446
channel <- err
5547
}()
5648
}
57-
// invoke java func
58-
x := make(map[string]interface{})
59-
x["name"] = "World"
60-
go func() {
61-
time.Sleep(5 * time.Second)
62-
err := invokeApiTest(javaFn.Name, x, HOST, PORT)
63-
channel <- err
64-
}()
6549
}
6650

6751
// wait for all functions to complete and checking the errors
68-
for i := 0; i < (len(pyFuncs)+1)*n; i++ {
52+
for i := 0; i < len(pyFuncs)*n; i++ {
6953
err := <-channel
7054
utils.AssertNil(t, err)
7155
}
7256
// delete each function
7357
for _, name := range pyFuncs {
7458
deleteApiTest(t, name, HOST, PORT)
7559
}
76-
deleteApiTest(t, javaFn.Name, HOST, PORT)
7760
//utils.AssertTrueMsg(t, workflow.IsEmptyPartialDataCache(), "partial data cache is not empty")
7861
}
7962

internal/test/aslparser_test.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,20 @@ func TestParsedWorkflowName(t *testing.T) {
3333
// commonTest creates a function, parses a json AWS State Language file producing a function composition,
3434
// then checks if the composition is saved onto ETCD. Lastly, it runs the composition and expects the correct result.
3535
func commonTest(t *testing.T, name string, paramName string, paramValue string) {
36-
all, err := workflow.GetAllWorkflows()
37-
utils.AssertNil(t, err)
38-
39-
//initializeAllPyFunctionFromNames(t, "inc", "double", "hello", "noop")
40-
4136
comp := parseFileName(t, name)
4237
defer func() {
43-
err = comp.Delete()
38+
err := comp.Delete()
4439
utils.AssertNilMsg(t, err, "failed to delete composition")
4540
}()
46-
// saving to etcd is not necessary to run the function composition, but is needed when offloading
47-
{
48-
err := comp.Save()
49-
utils.AssertNilMsg(t, err, "unable to save parsed composition")
5041

51-
all2, err := workflow.GetAllWorkflows()
52-
utils.AssertNil(t, err)
53-
utils.AssertEqualsMsg(t, len(all2), len(all)+1, "the number of created functions differs")
42+
// saving to etcd is not necessary to run the function composition, but is needed when offloading
43+
err := comp.Save()
44+
utils.AssertNilMsg(t, err, "unable to save parsed composition")
5445

55-
expectedComp, ok := workflow.Get(name)
56-
utils.AssertTrue(t, ok)
46+
expectedComp, ok := workflow.Get(name)
47+
utils.AssertTrue(t, ok)
5748

58-
utils.AssertTrueMsg(t, comp.Equals(expectedComp), "parsed composition differs from expected composition")
59-
}
49+
utils.AssertTrueMsg(t, comp.Equals(expectedComp), "parsed composition differs from expected composition")
6050

6151
// runs the workflow
6252
params := make(map[string]interface{})

internal/test/util.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/base64"
55
"encoding/json"
66
"fmt"
7+
"log"
78
"net/http"
89
"os"
910
"testing"
@@ -147,7 +148,11 @@ func initializeJsFunction(name string, sign *function.Signature) (*function.Func
147148
oldF, found := function.GetFunction(name)
148149
if found {
149150
// the function already exists; we delete it
150-
oldF.Delete()
151+
err := oldF.Delete()
152+
if err != nil {
153+
log.Printf("Function %s was not removed: %v", name, err)
154+
return nil, err
155+
}
151156
node.ShutdownWarmContainersFor(oldF)
152157
}
153158

0 commit comments

Comments
 (0)