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"
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. */
UNIT_TEST_FAILFAST = "${params.UNIT_TEST_FAILFAST}"
UNIT_TEST_RERUN_FAILS = "${params.UNIT_TEST_RERUN_FAILS}"
@ -121,28 +126,51 @@ pipeline {
stage('Unit Tests') {
environment {
TEST_POSTGRES_PORT = "${env.DB_PORT}"
NWAKU_REST_PORT = "${env.NWAKU_REST_PORT}"
}
steps { script {
def ipAddress = sh(script: "hostname -I | awk '{print \$1}'", returnStdout: true).trim()
db = docker.image('postgres:9.6-alpine').withRun([
"--name=${DB_CONT}",
"--env=POSTGRES_HOST_AUTH_METHOD=trust",
"--publish=${DB_PORT}:${DB_PORT}",
].join(' '), "-p ${DB_PORT}") { c ->
nix.shell('make generate-handlers', pure: true)
withCredentials([
string(
credentialsId: 'codeclimate-test-reporter-id',
variable: 'CC_TEST_REPORTER_ID'
),
]) {
nix.shell('make test-unit V=1', pure: false)
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)
withCredentials([
string(
credentialsId: 'codeclimate-test-reporter-id',
variable: 'CC_TEST_REPORTER_ID'
),
]) {
nix.shell('make test-unit V=1', pure: false)
}
sh "mv c.out test-coverage.out"
archiveArtifacts('test-coverage.out, coverage/codeclimate.json, test-coverage.html')
}
sh "mv c.out test-coverage.out"
archiveArtifacts('test-coverage.out, coverage/codeclimate.json, test-coverage.html')
}
} }
post { cleanup { /* Leftover DB containers. */
sh "docker rm ${DB_CONT} || true"
sh "docker rm ${NWAKU_CONT} || true"
} }
}
} // 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)
}
func TestBasicWakuV2(t *testing.T) {
t.Skip("flaky test")
func parseNodes(rec []string) []*enode.Node {
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")
if envEnrTreeAddress != "" {
enrTreeAddress = envEnrTreeAddress
@ -166,6 +191,7 @@ func TestBasicWakuV2(t *testing.T) {
config := &Config{}
setDefaultConfig(config, false)
config.Port = 0
config.Resolver = mapResolver(tree.ToTXT("n"))
config.DiscV5BootstrapNodes = []string{enrTreeAddress}
config.DiscoveryLimit = 20
config.WakuNodes = []string{enrTreeAddress}
@ -177,7 +203,7 @@ func TestBasicWakuV2(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second)
defer cancel()
discoveredNodes, err := dnsdisc.RetrieveNodes(ctx, enrTreeAddress)
discoveredNodes, err := dnsdisc.RetrieveNodes(ctx, enrTreeAddress, dnsdisc.WithResolver(config.Resolver))
require.NoError(t, err)
// Peer used for retrieving history
@ -192,7 +218,7 @@ func TestBasicWakuV2(t *testing.T) {
// Sanity check, not great, but it's probably helpful
err = tt.RetryWithBackOff(func() error {
if len(w.Peers()) < 2 {
if len(w.Peers()) < 1 {
return errors.New("no peers discovered")
}
return nil