diff --git a/smoke/tests/texture/node/index.js b/smoke/tests/texture/node/index.js new file mode 100644 index 00000000000..9dc329b2ff3 --- /dev/null +++ b/smoke/tests/texture/node/index.js @@ -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); diff --git a/smoke/tests/tool/container.go b/smoke/tests/tool/container.go index b5171a0a9ef..ef744efc0bd 100644 --- a/smoke/tests/tool/container.go +++ b/smoke/tests/tool/container.go @@ -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", @@ -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 { @@ -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) @@ -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())