From 4b7c5ba99b5509ef67fad4ef61a7fc4efac8d1aa Mon Sep 17 00:00:00 2001 From: Anton Litvinov Date: Mon, 9 Sep 2024 18:16:46 +0400 Subject: [PATCH] Transform test into e2e test Signed-off-by: Anton Litvinov --- ci/test/e2e.go | 30 +++++++++++ docker-compose.e2e-basic.yml | 12 +++++ e2e/bug6022/Dockerfile | 6 +++ e2e/bug6022/hello.go | 16 ++++++ .../bug6022}/shaper_service_test.go | 17 +++--- e2e/gorunner/Dockerfile.precompiled | 2 + e2e/runner.go | 52 +++++++++++++++++++ 7 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 e2e/bug6022/Dockerfile create mode 100644 e2e/bug6022/hello.go rename {services/wireguard/endpoint/netstack-provider => e2e/bug6022}/shaper_service_test.go (89%) diff --git a/ci/test/e2e.go b/ci/test/e2e.go index e14754b674..4928569f70 100644 --- a/ci/test/e2e.go +++ b/ci/test/e2e.go @@ -45,6 +45,17 @@ func BuildE2eTestBinary() error { if err != nil { return err } + err = sh.RunWith(crossCompileFlags, "go", "test", "-c", "./e2e/bug6022") + if err != nil { + return err + } + err = sh.RunWith(crossCompileFlags, "go", "build", "-o", "bug6022.aux", "./e2e/bug6022") + if err != nil { + return err + } + _ = os.Mkdir("./build/e2e/", os.ModeDir) + os.Rename("./bug6022.test", "./build/e2e/bug6022.test") + os.Rename("./bug6022.aux", "./build/e2e/bug6022.aux") _ = os.Mkdir("./build/e2e/", os.ModeDir) return os.Rename("./e2e.test", "./build/e2e/test") @@ -75,6 +86,25 @@ func TestE2EBasic() error { return runner.Test("myst-provider") } +func TestE2EShaper() error { + logconfig.Bootstrap() + + mg.Deps(BuildMystBinaryForE2eDocker, BuildE2eDeployerBinary) + + // not running this in parallel as it does some package switching magic + mg.Deps(BuildE2eTestBinary) + + composeFiles := []string{ + "./docker-compose.e2e-basic.yml", + } + runner, cleanup := e2e.NewRunner(composeFiles, "node_e2e_basic_test", "") + defer cleanup() + if err := runner.Init_(); err != nil { + return err + } + return runner.Test_() +} + // TestE2ENAT runs end-to-end tests in NAT environment func TestE2ENAT() error { logconfig.Bootstrap() diff --git a/docker-compose.e2e-basic.yml b/docker-compose.e2e-basic.yml index 9942256e0b..a70d8ddf4e 100644 --- a/docker-compose.e2e-basic.yml +++ b/docker-compose.e2e-basic.yml @@ -571,8 +571,20 @@ services: --observer.address="" daemon + bug6022-aux: + build: + context: . + dockerfile: ./e2e/bug6022/Dockerfile + cap_add: + - NET_ADMIN + working_dir: /node + expose: + - 8083 + #go runner to run go programs inside localnet (usefull for contract deployment or e2e test running) go-runner: + depends_on: + - bug6022-aux build: context: . dockerfile: ./e2e/gorunner/Dockerfile.precompiled diff --git a/e2e/bug6022/Dockerfile b/e2e/bug6022/Dockerfile new file mode 100644 index 0000000000..9dd46e65fa --- /dev/null +++ b/e2e/bug6022/Dockerfile @@ -0,0 +1,6 @@ +FROM alpine:3.12 + +#COPY ./build/e2e/bug6022.test /usr/local/bin/bug6022.test +COPY ./build/e2e/bug6022.aux /usr/local/bin/bug6022.aux + +ENTRYPOINT ["/usr/local/bin/bug6022.aux"] diff --git a/e2e/bug6022/hello.go b/e2e/bug6022/hello.go new file mode 100644 index 0000000000..2ead345559 --- /dev/null +++ b/e2e/bug6022/hello.go @@ -0,0 +1,16 @@ +package main + +import ( + "fmt" + "net/http" +) + +func main() { + http.HandleFunc("/", HelloServer) + http.ListenAndServe(":8083", nil) +} + +func HelloServer(w http.ResponseWriter, r *http.Request) { + fmt.Println(r.URL.Path, r.RemoteAddr) + fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:]) +} diff --git a/services/wireguard/endpoint/netstack-provider/shaper_service_test.go b/e2e/bug6022/shaper_service_test.go similarity index 89% rename from services/wireguard/endpoint/netstack-provider/shaper_service_test.go rename to e2e/bug6022/shaper_service_test.go index 4f4526f95a..a62f8cae1e 100644 --- a/services/wireguard/endpoint/netstack-provider/shaper_service_test.go +++ b/e2e/bug6022/shaper_service_test.go @@ -15,7 +15,7 @@ * along with this program. If not, see . */ -package netstack_provider +package main import ( "bytes" @@ -33,6 +33,7 @@ import ( "github.com/mysteriumnetwork/node/config" netstack "github.com/mysteriumnetwork/node/services/wireguard/endpoint/netstack" + netstack_provider "github.com/mysteriumnetwork/node/services/wireguard/endpoint/netstack-provider" ) func startClient(t *testing.T, priv, pubServ wgtypes.Key) { @@ -69,14 +70,16 @@ func startClient(t *testing.T, priv, pubServ wgtypes.Key) { }, } - resp, err := client.Get("http://107.173.23.19:8080/test") + resp, err := client.Get("http://bug6022-aux.local:8083/test") if err != nil { t.Error(err) + log.Println(err) return } body, err := io.ReadAll(resp.Body) if err != nil { t.Error(err) + log.Println(err) return } log.Println("Reply:", string(body)) @@ -87,12 +90,10 @@ func startClient(t *testing.T, priv, pubServ wgtypes.Key) { ok = "failed" } log.Println("Test result:", ok) - // dev.Down() - // tun.Close() } func startServer(t *testing.T, privKey, pubClinet wgtypes.Key) { - tun, _, _, err := CreateNetTUNWithStack( + tun, _, _, err := netstack_provider.CreateNetTUNWithStack( []netip.Addr{netip.MustParseAddr("192.168.4.1")}, 53, device.DefaultMTU, @@ -124,7 +125,11 @@ func TestShaperEnabled(t *testing.T) { config.Current.SetDefault(config.FlagShaperBandwidth.Name, "6250") config.Current.SetDefault(config.FlagShaperEnabled.Name, "true") - InitUserspaceShaper(nil) + netstack_provider.InitUserspaceShaper(nil) + + // log.Println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") + // t.Error(errors.New("!")) + // return privKey1, err := wgtypes.GeneratePrivateKey() if err != nil { diff --git a/e2e/gorunner/Dockerfile.precompiled b/e2e/gorunner/Dockerfile.precompiled index 72cc0a2bc3..e120eca06e 100644 --- a/e2e/gorunner/Dockerfile.precompiled +++ b/e2e/gorunner/Dockerfile.precompiled @@ -5,3 +5,5 @@ RUN ln -s /sbin/iptables /usr/sbin/iptables COPY ./build/e2e/test /usr/local/bin/test COPY ./build/e2e/deployer /usr/local/bin/deployer +COPY ./build/e2e/bug6022.test /usr/local/bin/bug6022.test +#COPY ./build/e2e/bug6022.aux /usr/local/bin/bug6022.aux diff --git a/e2e/runner.go b/e2e/runner.go index 8213183a7d..ceb82483ae 100644 --- a/e2e/runner.go +++ b/e2e/runner.go @@ -94,6 +94,40 @@ func (r *Runner) Test(providerHost string) (retErr error) { return } +// Test_ starts given provider and consumer nodes and runs e2e tests. +func (r *Runner) Test_() (retErr error) { +// services := strings.Split(r.services, ",") +// if err := r.startProviderConsumerNodes(providerHost, services); err != nil { +// retErr = errors.Wrap(err, "tests failed!") +// return +// } + +// defer func() { +// if err := r.stopProviderConsumerNodes(providerHost, services); err != nil { +// log.Err(err).Msg("Could not stop provider consumer nodes") +// } +// +// if retErr == nil { // check public IPs in logs only if all the tests succeeded +// if err := r.checkPublicIPInLogs("myst-provider", "myst-consumer-wireguard"); err != nil { +// retErr = errors.Wrap(err, "tests failed!") +// return +// } +// } +// }() + + log.Info().Msg("Running tests for env: " + r.testEnv) + log.Info().Msg("Running >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ") + + err := r.compose("run", "go-runner", +// "wget", "http://bug6022-aux:8083/test", + "/usr/local/bin/bug6022.test", + ) + + retErr = errors.Wrap(err, "tests failed!") + return +} + + func (r *Runner) checkPublicIPInLogs(containers ...string) error { regExps := []*regexp.Regexp{ regexp.MustCompile(`(^|[^0-9])(172\.30\.0\.2)($|[^0-9])`), @@ -204,6 +238,24 @@ func (r *Runner) Init() error { return nil } +func (r *Runner) Init_() error { + log.Info().Msg("Starting other services >>") + if err := r.compose("pull"); err != nil { + return errors.Wrap(err, "could not pull images") + } + + if err := r.compose("up", "-d", "bug6022-aux"); err != nil { + return errors.Wrap(err, "starting other services failed!") + } + + log.Info().Msg("Building app images") + if err := r.compose("build"); err != nil { + return errors.Wrap(err, "building app images failed!") + } + + return nil +} + func (r *Runner) startProviderConsumerNodes(providerHost string, services []string) error { log.Info().Msg("Starting provider consumer containers")