Skip to content

Commit

Permalink
[Emulator tests] Automate tests in kokoro and add helper to run proxy…
Browse files Browse the repository at this point in the history
… server (#2777)

* helper to start proxy server

* automate tests

* helper to start proxy server

* lint fix

* provide execute permission to script

* provide prot in function

* provide prot in function

* remove redundunt line

* review comment

* remove comment

* remove comment

* review comment

* remove unnecessary files

* removing port from argument as not require for now
  • Loading branch information
Tulsishah authored Dec 12, 2024
1 parent d04efd1 commit 090ab5c
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ action {
define_artifacts {
regex: "gcsfuse-failed-integration-test-logs-*"
strip_prefix: "github/gcsfuse/perfmetrics/scripts"
regex: "proxy*"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ action {
define_artifacts {
regex: "gcsfuse-failed-integration-test-logs-*"
strip_prefix: "github/gcsfuse/perfmetrics/scripts"
regex: "proxy*"
}
}

Expand Down
2 changes: 1 addition & 1 deletion tools/integration_tests/emulator_tests/emulator_tests.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ curl -X POST --data-binary @test.json \
rm test.json

# Run specific test suite
go test --integrationTest -v --testbucket=test-bucket -timeout 10m
go test ./tools/integration_tests/emulator_tests/... --integrationTest -v --testbucket=test-bucket -timeout 10m
86 changes: 86 additions & 0 deletions tools/integration_tests/emulator_tests/util/test_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package emulator_tests

import (
"fmt"
"log"
"os"
"os/exec"
"path"
"strconv"
"strings"
"syscall"

"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/setup"
)

// StartProxyServer starts a proxy server as a background process and handles its lifecycle.
//
// It launches the proxy server with the specified configuration and port, logs its output to a file.
func StartProxyServer(configPath string) {
// Start the proxy in the background
cmd := exec.Command("go", "run", "../proxy_server/.", "--config-path="+configPath)
logFileForProxyServer, err := os.Create(path.Join(os.Getenv("KOKORO_ARTIFACTS_DIR"), "proxy-"+setup.GenerateRandomString(5)))
if err != nil {
log.Fatal("Error in creating log file for proxy server.")
}
log.Printf("Proxy server logs are generated with specific filename %s: ", logFileForProxyServer.Name())
cmd.Stdout = logFileForProxyServer
cmd.Stderr = logFileForProxyServer
err = cmd.Start()
if err != nil {
log.Fatal(err)
}
}

// KillProxyServerProcess kills all processes listening on the specified port.
//
// It uses the `lsof` command to identify the processes and sends SIGINT to each of them.
func KillProxyServerProcess(port int) error {
// Use lsof to find processes listening on the specified port
cmd := exec.Command("lsof", "-i", fmt.Sprintf(":%d", port))
output, err := cmd.Output()
if err != nil {
return fmt.Errorf("error running lsof: %w", err)
}

// Parse the lsof output to get the process IDs
lines := strings.Split(string(output), "\n")
for _, line := range lines[1:] {
fields := strings.Fields(line)
if len(fields) > 1 {
pidStr := fields[1]
pid, err := strconv.Atoi(pidStr)
if err != nil {
log.Println("Error parsing process ID:", err)
continue
}

// Send SIGINT to the process
process, err := os.FindProcess(pid)
if err != nil {
log.Println("Error finding process:", err)
continue
}
err = process.Signal(syscall.SIGINT)
if err != nil {
log.Println("Error sending SIGINT to process:", err)
}
}
}

return nil
}
29 changes: 21 additions & 8 deletions tools/integration_tests/run_e2e_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ function run_e2e_tests_for_tpc() {
exit $exit_code
}

function run_e2e_tests_for_emulator() {
./tools/integration_tests/emulator_tests/emulator_tests.sh
}

#commenting it so cleanup and failure check happens for both
#set -e

Expand Down Expand Up @@ -342,6 +346,12 @@ function main(){
run_e2e_tests_for_flat_bucket &
e2e_tests_flat_bucket_pid=$!

run_e2e_tests_for_emulator &
e2e_tests_emulator_pid=$!

wait $e2e_tests_emulator_pid
e2e_tests_emulator_status=$?

wait $e2e_tests_flat_bucket_pid
e2e_tests_flat_bucket_status=$?

Expand All @@ -352,23 +362,26 @@ function main(){

print_test_logs

if [ $e2e_tests_flat_bucket_status != 0 ] && [ $e2e_tests_hns_bucket_status != 0 ];
then
echo "The e2e tests for both flat and hns bucket failed.."
exit 1
fi

exit_code=0
if [ $e2e_tests_flat_bucket_status != 0 ];
then
echo "The e2e tests for flat bucket failed.."
exit 1
exit_code=1
fi

if [ $e2e_tests_hns_bucket_status != 0 ];
then
echo "The e2e tests for hns bucket failed.."
exit 1
exit_code=1
fi

if [ $e2e_tests_emulator_status != 0 ];
then
echo "The e2e tests for emulator failed.."
exit_code=1
fi

exit $exit_code
}

#Main method to run script
Expand Down

0 comments on commit 090ab5c

Please sign in to comment.