chore_: fix `TestBasicWakuV2` (#5718)

This commit is contained in:
richΛrd 2024-08-15 14:43:37 -04:00 committed by GitHub
parent 93bb77f303
commit bb6d5f602b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 127 additions and 15 deletions

View File

@ -62,6 +62,11 @@ pipeline {
REPO_SRC = "${GOPATH}/src/github.com/status-im/status-go" REPO_SRC = "${GOPATH}/src/github.com/status-im/status-go"
BASE_BRANCH = "${env.CHANGE_TARGET}" BASE_BRANCH = "${env.CHANGE_TARGET}"
NWAKU_CONT = "status-go-test-nwaku-${env.EXECUTOR_NUMBER.toInteger() + 1}"
NWAKU_TCP_PORT = "${60000 + env.EXECUTOR_NUMBER.toInteger()}"
NWAKU_UDP_PORT = "${9000 + env.EXECUTOR_NUMBER.toInteger()}"
NWAKU_REST_PORT = "${9645 + env.EXECUTOR_NUMBER.toInteger()}"
/* Hack-fix for params not being set in env on first job run. */ /* Hack-fix for params not being set in env on first job run. */
UNIT_TEST_FAILFAST = "${params.UNIT_TEST_FAILFAST}" UNIT_TEST_FAILFAST = "${params.UNIT_TEST_FAILFAST}"
UNIT_TEST_RERUN_FAILS = "${params.UNIT_TEST_RERUN_FAILS}" UNIT_TEST_RERUN_FAILS = "${params.UNIT_TEST_RERUN_FAILS}"
@ -121,13 +126,34 @@ pipeline {
stage('Unit Tests') { stage('Unit Tests') {
environment { environment {
TEST_POSTGRES_PORT = "${env.DB_PORT}" TEST_POSTGRES_PORT = "${env.DB_PORT}"
NWAKU_REST_PORT = "${env.NWAKU_REST_PORT}"
} }
steps { script { steps { script {
def ipAddress = sh(script: "hostname -I | awk '{print \$1}'", returnStdout: true).trim()
db = docker.image('postgres:9.6-alpine').withRun([ db = docker.image('postgres:9.6-alpine').withRun([
"--name=${DB_CONT}", "--name=${DB_CONT}",
"--env=POSTGRES_HOST_AUTH_METHOD=trust", "--env=POSTGRES_HOST_AUTH_METHOD=trust",
"--publish=${DB_PORT}:${DB_PORT}", "--publish=${DB_PORT}:${DB_PORT}",
].join(' '), "-p ${DB_PORT}") { c -> ].join(' '), "-p ${DB_PORT}") { c ->
nwaku = docker.image('harbor.status.im/wakuorg/nwaku:latest').withRun([
"--name=${NWAKU_CONT}",
"--publish=${NWAKU_TCP_PORT}:${NWAKU_TCP_PORT}/tcp",
"--publish=${NWAKU_UDP_PORT}:${NWAKU_UDP_PORT}/udp",
"--publish=${NWAKU_REST_PORT}:8645/tcp"
].join(' '), [
"--tcp-port=${NWAKU_TCP_PORT}",
"--discv5-discovery=true",
"--cluster-id=16",
"--pubsub-topic=/waku/2/rs/16/32",
"--pubsub-topic=/waku/2/rs/16/64",
"--nat=extip:${ipAddress}",
"--discv5-discovery",
"--discv5-udp-port=${NWAKU_UDP_PORT}",
"--rest-address=0.0.0.0",
"--store",
"--filter",
"--lightpush"
].join(' ')) { c2 ->
nix.shell('make generate-handlers', pure: true) nix.shell('make generate-handlers', pure: true)
withCredentials([ withCredentials([
string( string(
@ -140,9 +166,11 @@ pipeline {
sh "mv c.out test-coverage.out" sh "mv c.out test-coverage.out"
archiveArtifacts('test-coverage.out, coverage/codeclimate.json, test-coverage.html') archiveArtifacts('test-coverage.out, coverage/codeclimate.json, test-coverage.html')
} }
}
} } } }
post { cleanup { /* Leftover DB containers. */ post { cleanup { /* Leftover DB containers. */
sh "docker rm ${DB_CONT} || true" sh "docker rm ${DB_CONT} || true"
sh "docker rm ${NWAKU_CONT} || true"
} } } }
} }
} // stages } // stages

58
wakuv2/nwaku.go Normal file
View File

@ -0,0 +1,58 @@
package wakuv2
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"strconv"
)
type NwakuInfo struct {
ListenAddresses []string `json:"listenAddresses"`
EnrUri string `json:"enrUri"`
}
func GetNwakuInfo(host *string, port *int) (NwakuInfo, error) {
nwakuRestPort := 8645
if port != nil {
nwakuRestPort = *port
}
envNwakuRestPort := os.Getenv("NWAKU_REST_PORT")
if envNwakuRestPort != "" {
v, err := strconv.Atoi(envNwakuRestPort)
if err != nil {
return NwakuInfo{}, err
}
nwakuRestPort = v
}
nwakuRestHost := "localhost"
if host != nil {
nwakuRestHost = *host
}
envNwakuRestHost := os.Getenv("NWAKU_REST_HOST")
if envNwakuRestHost != "" {
nwakuRestHost = envNwakuRestHost
}
resp, err := http.Get(fmt.Sprintf("http://%s:%d/debug/v1/info", nwakuRestHost, nwakuRestPort))
if err != nil {
return NwakuInfo{}, err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return NwakuInfo{}, err
}
var data NwakuInfo
err = json.Unmarshal(body, &data)
if err != nil {
return NwakuInfo{}, err
}
return data, nil
}

View File

@ -154,10 +154,35 @@ func TestRelayPeers(t *testing.T) {
require.Error(t, err) require.Error(t, err)
} }
func TestBasicWakuV2(t *testing.T) { func parseNodes(rec []string) []*enode.Node {
t.Skip("flaky test") var ns []*enode.Node
for _, r := range rec {
var n enode.Node
if err := n.UnmarshalText([]byte(r)); err != nil {
panic(err)
}
ns = append(ns, &n)
}
return ns
}
enrTreeAddress := testStoreENRBootstrap // In order to run these tests, you must run an nwaku node
//
// Using Docker:
//
// IP_ADDRESS=$(hostname -I | awk '{print $1}');
// docker run \
// -p 60000:60000/tcp -p 9000:9000/udp -p 8645:8645/tcp harbor.status.im/wakuorg/nwaku:v0.31.0 \
// --tcp-port=60000 --discv5-discovery=true --cluster-id=16 --pubsub-topic=/waku/2/rs/16/32 --pubsub-topic=/waku/2/rs/16/64 \
// --nat=extip:${IP_ADDRESS} --discv5-discovery --discv5-udp-port=9000 --rest-address=0.0.0.0 --store
func TestBasicWakuV2(t *testing.T) {
nwakuInfo, err := GetNwakuInfo(nil, nil)
require.NoError(t, err)
// Creating a fake DNS Discovery ENRTree
tree, url := makeTestTree("n", parseNodes([]string{nwakuInfo.EnrUri}), nil)
enrTreeAddress := url
envEnrTreeAddress := os.Getenv("ENRTREE_ADDRESS") envEnrTreeAddress := os.Getenv("ENRTREE_ADDRESS")
if envEnrTreeAddress != "" { if envEnrTreeAddress != "" {
enrTreeAddress = envEnrTreeAddress enrTreeAddress = envEnrTreeAddress
@ -166,6 +191,7 @@ func TestBasicWakuV2(t *testing.T) {
config := &Config{} config := &Config{}
setDefaultConfig(config, false) setDefaultConfig(config, false)
config.Port = 0 config.Port = 0
config.Resolver = mapResolver(tree.ToTXT("n"))
config.DiscV5BootstrapNodes = []string{enrTreeAddress} config.DiscV5BootstrapNodes = []string{enrTreeAddress}
config.DiscoveryLimit = 20 config.DiscoveryLimit = 20
config.WakuNodes = []string{enrTreeAddress} config.WakuNodes = []string{enrTreeAddress}
@ -177,7 +203,7 @@ func TestBasicWakuV2(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second) ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second)
defer cancel() defer cancel()
discoveredNodes, err := dnsdisc.RetrieveNodes(ctx, enrTreeAddress) discoveredNodes, err := dnsdisc.RetrieveNodes(ctx, enrTreeAddress, dnsdisc.WithResolver(config.Resolver))
require.NoError(t, err) require.NoError(t, err)
// Peer used for retrieving history // Peer used for retrieving history
@ -192,7 +218,7 @@ func TestBasicWakuV2(t *testing.T) {
// Sanity check, not great, but it's probably helpful // Sanity check, not great, but it's probably helpful
err = tt.RetryWithBackOff(func() error { err = tt.RetryWithBackOff(func() error {
if len(w.Peers()) < 2 { if len(w.Peers()) < 1 {
return errors.New("no peers discovered") return errors.New("no peers discovered")
} }
return nil return nil