Skip to content

Commit

Permalink
Transform test into e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Litvinov <[email protected]>
  • Loading branch information
Zensey committed Sep 9, 2024
1 parent f916db2 commit 4b7c5ba
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 6 deletions.
30 changes: 30 additions & 0 deletions ci/test/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -75,6 +86,25 @@ func TestE2EBasic() error {
return runner.Test("myst-provider")
}

func TestE2EShaper() error {

Check failure on line 89 in ci/test/e2e.go

View workflow job for this annotation

GitHub Actions / unit-tests

exported function TestE2EShaper should have comment or be unexported
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()
Expand Down
12 changes: 12 additions & 0 deletions docker-compose.e2e-basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions e2e/bug6022/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
16 changes: 16 additions & 0 deletions e2e/bug6022/hello.go
Original file line number Diff line number Diff line change
@@ -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) {

Check failure on line 13 in e2e/bug6022/hello.go

View workflow job for this annotation

GitHub Actions / unit-tests

exported function HelloServer should have comment or be unexported
fmt.Println(r.URL.Path, r.RemoteAddr)
fmt.Fprintf(w, "Hello, %s!", r.URL.Path[1:])
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package netstack_provider
package main

import (
"bytes"
Expand All @@ -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) {
Expand Down Expand Up @@ -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))
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions e2e/gorunner/Dockerfile.precompiled
Original file line number Diff line number Diff line change
Expand Up @@ -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
52 changes: 52 additions & 0 deletions e2e/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])`),
Expand Down Expand Up @@ -204,6 +238,24 @@ func (r *Runner) Init() error {
return nil
}

func (r *Runner) Init_() error {

Check failure on line 241 in e2e/runner.go

View workflow job for this annotation

GitHub Actions / unit-tests

exported method Runner.Init_ should have comment or be unexported
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")

Expand Down

0 comments on commit 4b7c5ba

Please sign in to comment.