Skip to content

Commit

Permalink
Updated top module API and tests
Browse files Browse the repository at this point in the history
Signed-off-by: Plamen Petrov <plamb0brt@gmail.com>
  • Loading branch information
plamenmpetrov authored and ustiugov committed Jul 22, 2020
1 parent 7007b48 commit f81de92
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 343 deletions.
12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ clean:
test-all: test $(SUBDIRS) test-man

test:
sudo env "PATH=$(PATH)" go test $(EXTRATESTFILES) $(EXTRAGOARGS)
sudo env "PATH=$(PATH)" "GOORCHSNAPSHOTS=false" go test $(EXTRATESTFILES) $(EXTRAGOARGS)
sudo env "PATH=$(PATH)" "GOORCHSNAPSHOTS=true" go test $(EXTRATESTFILES) $(EXTRAGOARGS)
./scripts/clean_fcctr.sh

test-man:
sudo env "PATH=$(PATH)" go test $(EXTRAGOARGS_NORACE) -run TestParallelLoadServe
sudo env "PATH=$(PATH)" go test $(EXTRAGOARGS) -run TestLoadServeMultiple1
sudo env "PATH=$(PATH)" go test $(EXTRAGOARGS) -run TestLoadServeMultiple2
sudo env "PATH=$(PATH)" go test $(EXTRAGOARGS) -run TestLoadServeMultiple3
sudo env "PATH=$(PATH)" "GOORCHSNAPSHOTS=false" go test $(EXTRAGOARGS_NORACE) -run TestParallelServe
sudo env "PATH=$(PATH)" "GOORCHSNAPSHOTS=false" go test $(EXTRAGOARGS) -run TestServeThree
sudo env "PATH=$(PATH)" "GOORCHSNAPSHOTS=true" go test $(EXTRAGOARGS_NORACE) -run TestParallelServe
sudo env "PATH=$(PATH)" "GOORCHSNAPSHOTS=true" go test $(EXTRAGOARGS) -run TestServeThree
./scripts/clean_fcctr.sh

$(SUBDIRS):
Expand Down
25 changes: 3 additions & 22 deletions failing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ package main

import (
"context"
"fmt"
"testing"
"time"

"github.com/stretchr/testify/require"
)
Expand All @@ -37,33 +35,16 @@ func TestServePauseSnapLoadServe(t *testing.T) {
imageName := "ustiugov/helloworld:runner_workload"
funcPool = NewFuncPool(false, 0, 0, true)

resp, err := funcPool.Serve(context.Background(), fID, imageName, "world", false)
resp, err := funcPool.Serve(context.Background(), fID, imageName, "world")
require.NoError(t, err, "Function returned error on 1st run")
require.Equal(t, resp.IsColdStart, true)
require.Equal(t, resp.Payload, "Hello, world!")

_, err = orch.PauseVM(context.Background(), fmt.Sprintf(fID+"_0"))
require.NoError(t, err, "Error when pausing VM")

_, err = orch.CreateSnapshot(context.Background(), fmt.Sprintf(fID+"_0"), "/tmp/snap_test", "/tmp/mem_test")
require.NoError(t, err, "Error when creating snapshot of VM")

_, err = orch.Offload(context.Background(), fmt.Sprintf(fID+"_0"))
require.NoError(t, err, "Failed to offload VM, "+"")

time.Sleep(300 * time.Millisecond)

_, err = orch.LoadSnapshot(context.Background(), fmt.Sprintf(fID+"_0"), "/tmp/snap_test", "/tmp/mem_test", false)
require.NoError(t, err, "Failed to load snapshot of VM, "+"")

_, err = orch.ResumeVM(context.Background(), fmt.Sprintf(fID+"_0"))
require.NoError(t, err, "Error when resuming VM")

resp, err = funcPool.Serve(context.Background(), fID, imageName, "world", false)
resp, err = funcPool.Serve(context.Background(), fID, imageName, "world")
require.NoError(t, err, "Function returned error on 2nd run")
require.Equal(t, resp.Payload, "Hello, world!")

// Breaks here because removing instance does not work
message, err := funcPool.RemoveInstance(fID, imageName)
message, err := funcPool.RemoveInstance(fID, imageName, true)
require.NoError(t, err, "Function returned error, "+message)
}
8 changes: 4 additions & 4 deletions fccd-orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func main() {
}
}

orch = ctriface.NewOrchestrator(*snapshotter, *niNum, ctriface.WithTestModeOn(false), ctriface.WithSnapshotsEnabled(true))
orch = ctriface.NewOrchestrator(*snapshotter, *niNum, ctriface.WithTestModeOn(false), ctriface.WithSnapshots(true))

funcPool = NewFuncPool(*isSaveMemory, *servedThreshold, *pinnedFuncNum, false)

Expand Down Expand Up @@ -148,7 +148,7 @@ func (s *server) StartVM(ctx context.Context, in *pb.StartVMReq) (*pb.StartVMRes
imageName := in.GetImage()
log.WithFields(log.Fields{"fID": fID, "image": imageName}).Info("Received direct StartVM")

message, err := funcPool.AddInstance(fID, imageName, false)
message, err := funcPool.AddInstance(fID, imageName)
tProfile := "not supported anymore"
//message, tProfile, err := orch.StartVM(ctx, fID, imageName)
if err != nil { // does not return error
Expand All @@ -161,7 +161,7 @@ func (s *server) StartVM(ctx context.Context, in *pb.StartVMReq) (*pb.StartVMRes
func (s *server) StopSingleVM(ctx context.Context, in *pb.StopSingleVMReq) (*pb.Status, error) {
fID := in.GetId()
log.WithFields(log.Fields{"fID": fID}).Info("Received direct StopVM")
message, err := funcPool.RemoveInstance(fID, "bogus imageName") //orch.StopSingleVM(ctx, vmID)
message, err := funcPool.RemoveInstance(fID, "bogus imageName", true) //orch.StopSingleVM(ctx, vmID)
if err != nil {
log.Warn(message, err)
}
Expand Down Expand Up @@ -189,5 +189,5 @@ func (s *fwdServer) FwdHello(ctx context.Context, in *hpb.FwdHelloReq) (*hpb.Fwd
logger := log.WithFields(log.Fields{"fID": fID, "image": imageName, "payload": payload})
logger.Debug("Received FwdHelloVM")

return funcPool.Serve(ctx, fID, imageName, payload, false)
return funcPool.Serve(ctx, fID, imageName, payload)
}
132 changes: 42 additions & 90 deletions fccd-orchestrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ package main

import (
"context"
"fmt"
"os"
"strconv"
"sync"
"testing"
"time"

ctrdlog "github.com/containerd/containerd/log"
log "github.com/sirupsen/logrus"
Expand All @@ -48,13 +46,25 @@ func TestMain(m *testing.M) {

log.SetOutput(os.Stdout)

log.SetLevel(log.DebugLevel)
log.SetLevel(log.InfoLevel)

orch = ctriface.NewOrchestrator("devmapper", 10, ctriface.WithTestModeOn(true), ctriface.WithSnapshotsEnabled(true))
var envSetting = os.Getenv("GOORCHSNAPSHOTS")
if envSetting == "" {
envSetting = "false"
}

log.Infof("Orchestrator snapshots enabled: %s", envSetting)

envBool, err := strconv.ParseBool(envSetting)
if err != nil {
log.Panic("Invalid snapshots mode environment variable")
}

orch = ctriface.NewOrchestrator("devmapper", 10, ctriface.WithTestModeOn(true), ctriface.WithSnapshots(envBool))

ret := m.Run()

err := orch.StopActiveVMs()
err = orch.StopActiveVMs()
if err != nil {
log.Printf("Failed to stop VMs, err: %v\n", err)
}
Expand All @@ -64,70 +74,13 @@ func TestMain(m *testing.M) {
os.Exit(ret)
}

func TestPauseResumeSerial(t *testing.T) {
fID := "1"
imageName := "ustiugov/helloworld:runner_workload"
funcPool = NewFuncPool(false, 0, 0, true)

resp, err := funcPool.Serve(context.Background(), fID, imageName, "world", false)
require.NoError(t, err, "Function returned error on 1st run")
require.Equal(t, resp.IsColdStart, true)
require.Equal(t, resp.Payload, "Hello, world!")

_, err = orch.PauseVM(context.Background(), fmt.Sprintf(fID+"_0"))
require.NoError(t, err, "Error when pausing VM")

// NOTE: Current implementation just return error but does not time out
//timeout_ctx, _ := context.WithTimeout(context.Background(), 20*time.Second)
resp, err = funcPool.Serve(context.Background(), fID, imageName, "world", false)
require.Error(t, err, "Function did not time out on 2nd run")
require.Equal(t, resp.Payload, "")

_, err = orch.ResumeVM(context.Background(), fmt.Sprintf(fID+"_0"))
require.NoError(t, err, "Error when resuming VM")

resp, err = funcPool.Serve(context.Background(), fID, imageName, "world", false)
require.NoError(t, err, "Function returned error on 3rd run")
require.Equal(t, resp.Payload, "Hello, world!")

message, err := funcPool.RemoveInstance(fID, imageName)
require.NoError(t, err, "Function returned error, "+message)
}

func TestServePauseSnapResumeServe(t *testing.T) {
fID := "2"
imageName := "ustiugov/helloworld:runner_workload"
funcPool = NewFuncPool(false, 0, 0, true)

resp, err := funcPool.Serve(context.Background(), fID, imageName, "world", false)
require.NoError(t, err, "Function returned error on 1st run")
require.Equal(t, resp.IsColdStart, true)
require.Equal(t, resp.Payload, "Hello, world!")

_, err = orch.PauseVM(context.Background(), fmt.Sprintf(fID+"_0"))
require.NoError(t, err, "Error when pausing VM")

_, err = orch.CreateSnapshot(context.Background(), fmt.Sprintf(fID+"_0"), "/tmp/snap_test", "/tmp/mem_test")
require.NoError(t, err, "Error when creating snapshot of VM")

_, err = orch.ResumeVM(context.Background(), fmt.Sprintf(fID+"_0"))
require.NoError(t, err, "Error when resuming VM")

resp, err = funcPool.Serve(context.Background(), fID, imageName, "world", false)
require.NoError(t, err, "Function returned error on 2nd run")
require.Equal(t, resp.Payload, "Hello, world!")

message, err := funcPool.RemoveInstance(fID, imageName)
require.NoError(t, err, "Function returned error, "+message)
}

func TestSendToFunctionSerial(t *testing.T) {
fID := "7"
fID := "1"
imageName := "ustiugov/helloworld:runner_workload"
funcPool = NewFuncPool(false, 0, 0, true)

for i := 0; i < 2; i++ {
resp, err := funcPool.Serve(context.Background(), fID, imageName, "world", false)
resp, err := funcPool.Serve(context.Background(), fID, imageName, "world")
require.NoError(t, err, "Function returned error")
if i == 0 {
require.Equal(t, resp.IsColdStart, true)
Expand All @@ -136,12 +89,12 @@ func TestSendToFunctionSerial(t *testing.T) {
require.Equal(t, resp.Payload, "Hello, world!")
}

message, err := funcPool.RemoveInstance(fID, imageName)
message, err := funcPool.RemoveInstance(fID, imageName, true)
require.NoError(t, err, "Function returned error, "+message)
}

func TestSendToFunctionParallel(t *testing.T) {
fID := "8"
fID := "2"
imageName := "ustiugov/helloworld:runner_workload"
funcPool = NewFuncPool(false, 0, 0, true)

Expand All @@ -151,33 +104,32 @@ func TestSendToFunctionParallel(t *testing.T) {

go func(i int) {
defer vmGroup.Done()
resp, err := funcPool.Serve(context.Background(), fID, imageName, "world", false)
resp, err := funcPool.Serve(context.Background(), fID, imageName, "world")
require.NoError(t, err, "Function returned error")
require.Equal(t, resp.Payload, "Hello, world!")
}(i)

}
vmGroup.Wait()

message, err := funcPool.RemoveInstance(fID, imageName)
message, err := funcPool.RemoveInstance(fID, imageName, true)
require.NoError(t, err, "Function returned error, "+message)
}

func TestStartSendStopTwice(t *testing.T) {
fID := "9"
fID := "3"
imageName := "ustiugov/helloworld:runner_workload"
funcPool = NewFuncPool(false, 1, 2, true)

for i := 0; i < 2; i++ {
for k := 0; k < 2; k++ {
resp, err := funcPool.Serve(context.Background(), fID, imageName, "world", false)
resp, err := funcPool.Serve(context.Background(), fID, imageName, "world")
require.NoError(t, err, "Function returned error")
require.Equal(t, resp.Payload, "Hello, world!")
}

message, err := funcPool.RemoveInstance(fID, imageName)
message, err := funcPool.RemoveInstance(fID, imageName, true)
require.NoError(t, err, "Function returned error, "+message)
time.Sleep(300 * time.Millisecond)
}

servedGot := funcPool.stats.statMap[fID].served
Expand All @@ -191,11 +143,11 @@ func TestStatsNotNumericFunction(t *testing.T) {
imageName := "ustiugov/helloworld:runner_workload"
funcPool = NewFuncPool(true, 1, 2, true)

resp, err := funcPool.Serve(context.Background(), fID, imageName, "world", false)
resp, err := funcPool.Serve(context.Background(), fID, imageName, "world")
require.NoError(t, err, "Function returned error")
require.Equal(t, resp.Payload, "Hello, world!")

message, err := funcPool.RemoveInstance(fID, imageName)
message, err := funcPool.RemoveInstance(fID, imageName, true)
require.NoError(t, err, "Function returned error, "+message)

servedGot := funcPool.stats.statMap[fID].served
Expand All @@ -205,15 +157,15 @@ func TestStatsNotNumericFunction(t *testing.T) {
}

func TestStatsNotColdFunction(t *testing.T) {
fID := "10"
fID := "4"
imageName := "ustiugov/helloworld:runner_workload"
funcPool = NewFuncPool(true, 1, 11, true)
funcPool = NewFuncPool(true, 1, 4, true)

resp, err := funcPool.Serve(context.Background(), fID, imageName, "world", false)
resp, err := funcPool.Serve(context.Background(), fID, imageName, "world")
require.NoError(t, err, "Function returned error")
require.Equal(t, resp.Payload, "Hello, world!")

message, err := funcPool.RemoveInstance(fID, imageName)
message, err := funcPool.RemoveInstance(fID, imageName, true)
require.NoError(t, err, "Function returned error, "+message)

servedGot := funcPool.stats.statMap[fID].served
Expand All @@ -223,25 +175,25 @@ func TestStatsNotColdFunction(t *testing.T) {
}

func TestSaveMemorySerial(t *testing.T) {
fID := "11"
fID := "5"
imageName := "ustiugov/helloworld:runner_workload"
funcPool = NewFuncPool(true, 40, 2, true)

for i := 0; i < 100; i++ {
resp, err := funcPool.Serve(context.Background(), fID, imageName, "world", false)
resp, err := funcPool.Serve(context.Background(), fID, imageName, "world")
require.NoError(t, err, "Function returned error")
require.Equal(t, resp.Payload, "Hello, world!")
}

startsGot := funcPool.stats.statMap[fID].started
require.Equal(t, 3, int(startsGot), "Cold start (starts) stats are wrong")

message, err := funcPool.RemoveInstance(fID, imageName)
message, err := funcPool.RemoveInstance(fID, imageName, true)
require.NoError(t, err, "Function returned error, "+message)
}

func TestSaveMemoryParallel(t *testing.T) {
fID := "12"
fID := "6"
imageName := "ustiugov/helloworld:runner_workload"
funcPool = NewFuncPool(true, 40, 2, true)

Expand All @@ -252,7 +204,7 @@ func TestSaveMemoryParallel(t *testing.T) {
go func(i int) {
defer vmGroup.Done()

resp, err := funcPool.Serve(context.Background(), fID, imageName, "world", false)
resp, err := funcPool.Serve(context.Background(), fID, imageName, "world")
require.NoError(t, err, "Function returned error")
require.Equal(t, resp.Payload, "Hello, world!")
}(i)
Expand All @@ -263,23 +215,23 @@ func TestSaveMemoryParallel(t *testing.T) {
startsGot := funcPool.stats.statMap[fID].started
require.Equal(t, 3, int(startsGot), "Cold start (starts) stats are wrong")

message, err := funcPool.RemoveInstance(fID, imageName)
message, err := funcPool.RemoveInstance(fID, imageName, true)
require.NoError(t, err, "Function returned error, "+message)
}

func TestDirectStartStopVM(t *testing.T) {
fID := "13"
fID := "7"
imageName := "ustiugov/helloworld:runner_workload"
funcPool = NewFuncPool(false, 0, 0, true)

message, err := funcPool.AddInstance(fID, imageName, false)
message, err := funcPool.AddInstance(fID, imageName)
require.NoError(t, err, "This error should never happen (addInstance())"+message)

resp, err := funcPool.Serve(context.Background(), fID, imageName, "world", false)
resp, err := funcPool.Serve(context.Background(), fID, imageName, "world")
require.NoError(t, err, "Function returned error")
require.Equal(t, resp.Payload, "Hello, world!")

message, err = funcPool.RemoveInstance(fID, imageName)
message, err = funcPool.RemoveInstance(fID, imageName, true)
require.NoError(t, err, "Function returned error, "+message)
}

Expand Down Expand Up @@ -307,7 +259,7 @@ func TestAllFunctions(t *testing.T) {
go func(fID int, imageName, request, response string) {
defer vmGroup.Done()

resp, err := funcPool.Serve(context.Background(), strconv.Itoa(fID), imageName, request, false)
resp, err := funcPool.Serve(context.Background(), strconv.Itoa(8+fID), imageName, request)
require.NoError(t, err, "Function returned error")

require.Equal(t, resp.Payload, "Hello, "+response+"!")
Expand All @@ -323,7 +275,7 @@ func TestAllFunctions(t *testing.T) {
go func(fID int, imageName string) {
defer vmGroup.Done()

message, err := funcPool.RemoveInstance(strconv.Itoa(fID), imageName)
message, err := funcPool.RemoveInstance(strconv.Itoa(8+fID), imageName, true)
require.NoError(t, err, "Function returned error, "+message)
}(fID, imageName)
}
Expand Down
Loading

0 comments on commit f81de92

Please sign in to comment.