Skip to content

Commit

Permalink
smoke: benchamrk support node
Browse files Browse the repository at this point in the history
Signed-off-by: Yadong Ding <ding_yadong@foxmail.com>
  • Loading branch information
Desiki-high committed Dec 1, 2023
1 parent f1de095 commit e7b358f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
10 changes: 10 additions & 0 deletions smoke/tests/texture/node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Load the http module to create an http server.
var http = require('http');

// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("hello\n");
});

server.listen(80);
36 changes: 31 additions & 5 deletions smoke/tests/tool/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,17 @@ type ContainerMetrics struct {

type RunArgs struct {
WaitURL string
Arg string
Mount mountPath
BaselineReadCount map[string]uint64
BaselineReadAmount map[string]uint64
}

type mountPath struct {
source string
target string
}

var URL_WAIT = map[string]RunArgs{
"wordpress": {
WaitURL: "http://localhost:80",
Expand All @@ -47,9 +54,17 @@ var URL_WAIT = map[string]RunArgs{
"zran": 79836339,
},
},
"node": {
WaitURL: "http://localhost:80",
Arg: "node /src/index.js",
Mount: mountPath{
source: "tests/texture/node",
target: "/src",
},
},
}

var supportContainerImages = []string{"wordpress"}
var supportContainerImages = []string{"wordpress", "node"}

// SupportContainerImage help to check if we support the image or not
func SupportContainerImage(image string) bool {
Expand All @@ -67,7 +82,15 @@ func contains(slice []string, value string) bool {

// runUrlWaitContainer run Contaienr util geting http response from WaitUrl
func runUrlWaitContainer(t *testing.T, image string, containerName string, runArgs RunArgs) {
cmd := fmt.Sprintf("sudo nerdctl --insecure-registry --snapshotter nydus run -d --net=host --name=%s %s", containerName, image)
cmd := "sudo nerdctl --insecure-registry --snapshotter nydus run -d --net=host"
if runArgs.Mount.source != "" {
currentDir, err := os.Getwd()
if err != nil {
t.Fatalf("can't get rooted path name")
}
cmd += fmt.Sprintf(" --volume %s:%s", filepath.Join(currentDir, runArgs.Mount.source), runArgs.Mount.target)
}
cmd += fmt.Sprintf(" --name=%s %s %s", containerName, image, runArgs.Arg)
RunWithoutOutput(t, cmd)
for {
resp, err := http.Get(runArgs.WaitURL)
Expand Down Expand Up @@ -103,14 +126,17 @@ func RunContainerWithBaseline(t *testing.T, image string, containerName string,
// RunContainer and return container metric
func RunContainer(t *testing.T, image string, containerName string) *ContainerMetrics {
var containerMetic ContainerMetrics
startTime := time.Now()

// runContainer
args, ok := URL_WAIT[ImageRepo(t, image)]
if ok {
startTime := time.Now()
runUrlWaitContainer(t, image, containerName, args)
endTime := time.Now()
containerMetic.E2ETime = endTime.Sub(startTime)
defer clearContainer(t, image, containerName)
}

endTime := time.Now()
containerMetic.E2ETime = endTime.Sub(startTime)
backendMetrics, err := getContainerBackendMetrics(t)
if err != nil {
t.Logf(err.Error())
Expand Down

0 comments on commit e7b358f

Please sign in to comment.