Skip to content

Commit 1f77c0a

Browse files
committed
Fix: function deletion not followed by container destruction in tests
1 parent 01e98f6 commit 1f77c0a

8 files changed

Lines changed: 53 additions & 7 deletions

File tree

examples/inc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
def handler(params, context):
2+
print(f"Invoked inc with input: {params}")
23
return int(params["input"]) + 1

images/base-alpine/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.20-alpine AS build
1+
FROM golang:1.21-alpine AS build
22

33
WORKDIR /sedge
44

internal/container/container.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ func Execute(contID ContainerID, req *executor.InvocationRequest) (*executor.Inv
6868
if resp.StatusCode != 200 {
6969
buffer, err2 := io.ReadAll(resp.Body)
7070
if err2 != nil {
71-
return nil, waitDuration, fmt.Errorf("function invocation with params: %s failed with status %s: - can't get response buffer %v", postBodyB, resp.Status, err2)
71+
return nil, waitDuration, fmt.Errorf("function invocation %v failed with status %s: - can't get response buffer %v", req, resp.Status, err2)
7272
}
73-
return nil, waitDuration, fmt.Errorf("function invocation with params: %s failed with status %s: %s", postBodyB, resp.Status, buffer)
73+
return nil, waitDuration, fmt.Errorf("function invocation %v failed with status %s: %s", req, resp.Status, buffer)
7474
}
7575
defer func(Body io.ReadCloser) {
7676
err := Body.Close()

internal/container/docker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,5 @@ func (cf *DockerFactory) GetLog(contID ContainerID) (string, error) {
165165
if err != nil {
166166
return "no logs", fmt.Errorf("can't read the logs: %v", err)
167167
}
168-
return fmt.Sprintf("%s\n", logs), nil
168+
return string(logs[:]), nil
169169
}

internal/scheduling/execution.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package scheduling
33
import (
44
"fmt"
55
"github.com/serverledge-faas/serverledge/internal/function"
6+
"log"
67
"time"
78

89
"github.com/serverledge-faas/serverledge/internal/container"
@@ -13,7 +14,8 @@ const HANDLER_DIR = "/app"
1314

1415
// Execute serves a request on the specified container.
1516
func Execute(contID container.ContainerID, r *scheduledRequest, isWarm bool) (function.ExecutionReport, error) {
16-
//log.Printf("[%s] Executing on container: %v", r.Fun, contID)
17+
18+
log.Printf("[%s] Executing on container: %v", r.Fun, contID)
1719

1820
var req executor.InvocationRequest
1921
if r.Fun.Runtime == container.CUSTOM_RUNTIME {
@@ -38,14 +40,20 @@ func Execute(contID container.ContainerID, r *scheduledRequest, isWarm bool) (fu
3840
response, invocationWait, err := container.Execute(contID, &req)
3941

4042
if err != nil {
43+
logs, errLog := container.GetLog(contID)
44+
if errLog == nil {
45+
fmt.Println(logs)
46+
} else {
47+
fmt.Printf("Failed to get log: %v\n", errLog)
48+
}
49+
4150
// notify scheduler
4251
completions <- &completionNotification{fun: r.Fun, contID: contID, executionReport: nil}
43-
return function.ExecutionReport{}, fmt.Errorf("[%s] Execution failed: %v", r, err)
52+
return function.ExecutionReport{}, fmt.Errorf("[%s] Execution failed on container %v: %v ", r, contID, err)
4453
}
4554

4655
if !response.Success {
4756
// notify scheduler
48-
//TODO: logs, errLogs := container.GetLog(contID)
4957
completions <- &completionNotification{fun: r.Fun, contID: contID, executionReport: nil}
5058
return function.ExecutionReport{}, fmt.Errorf("Function execution failed")
5159
}

internal/test/api_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ func TestCreateWorkflow(t *testing.T) {
6363
t.Skip("Skipping integration test")
6464
}
6565
fcName := "sequence"
66+
oldW, found := workflow.Get(fcName)
67+
if found {
68+
oldW.Delete()
69+
}
70+
6671
fn, err := InitializePyFunction("inc", "handler", function.NewSignature().
6772
AddInput("input", function.Int{}).
6873
AddOutput("result", function.Int{}).

internal/test/util.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/base64"
55
"encoding/json"
66
"fmt"
7+
"github.com/serverledge-faas/serverledge/internal/node"
78
"net/http"
89
"os"
910
"testing"
@@ -19,6 +20,13 @@ const PY_MEMORY = 20
1920
const JS_MEMORY = 50
2021

2122
func initializeExamplePyFunction() (*function.Function, error) {
23+
oldF, found := function.GetFunction("inc")
24+
if found {
25+
// the function already exists; we delete it
26+
oldF.Delete()
27+
node.ShutdownWarmContainersFor(oldF)
28+
}
29+
2230
srcPath := "../../examples/inc.py"
2331
srcContent, err := cli.ReadSourcesAsTar(srcPath)
2432
if err != nil {
@@ -43,6 +51,13 @@ func initializeExamplePyFunction() (*function.Function, error) {
4351
}
4452

4553
func initializeExampleJSFunction() (*function.Function, error) {
54+
oldF, found := function.GetFunction("inc")
55+
if found {
56+
// the function already exists; we delete it
57+
oldF.Delete()
58+
node.ShutdownWarmContainersFor(oldF)
59+
}
60+
4661
srcPath := "../../examples/inc.js"
4762
srcContent, err := cli.ReadSourcesAsTar(srcPath)
4863
if err != nil {
@@ -66,6 +81,14 @@ func initializeExampleJSFunction() (*function.Function, error) {
6681
}
6782

6883
func InitializePyFunction(name string, handler string, sign *function.Signature) (*function.Function, error) {
84+
85+
oldF, found := function.GetFunction(name)
86+
if found {
87+
// the function already exists; we delete it
88+
oldF.Delete()
89+
node.ShutdownWarmContainersFor(oldF)
90+
}
91+
6992
srcPath := "../../examples/" + name + ".py"
7093
srcContent, err := cli.ReadSourcesAsTar(srcPath)
7194
if err != nil {
@@ -86,6 +109,13 @@ func InitializePyFunction(name string, handler string, sign *function.Signature)
86109
}
87110

88111
func initializeJsFunction(name string, sign *function.Signature) (*function.Function, error) {
112+
oldF, found := function.GetFunction(name)
113+
if found {
114+
// the function already exists; we delete it
115+
oldF.Delete()
116+
node.ShutdownWarmContainersFor(oldF)
117+
}
118+
89119
srcPath := "../../examples/" + name + ".js"
90120
srcContent, err := cli.ReadSourcesAsTar(srcPath)
91121
if err != nil {

internal/workflow/scheduler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package workflow
22

33
import (
4+
"log"
45
"time"
56

67
"github.com/serverledge-faas/serverledge/internal/function"
@@ -20,6 +21,7 @@ func SubmitWorkflowInvocationRequest(req *Request) error {
2021
func SubmitAsyncWorkflowInvocationRequest(req *Request) {
2122
executionReport, errInvoke := req.W.Invoke(req)
2223
if errInvoke != nil {
24+
log.Println(errInvoke)
2325
PublishAsyncInvocationResponse(req.Id, InvocationResponse{Success: false})
2426
return
2527
}

0 commit comments

Comments
 (0)