Skip to content

Commit a48cba7

Browse files
authored
Merge pull request #704 from rabbitmq/cluster-test
Test that nodes cluster correctly
2 parents baf4579 + e6e9a7e commit a48cba7

File tree

2 files changed

+22
-30
lines changed

2 files changed

+22
-30
lines changed

system_tests/system_test.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"crypto/tls"
1515
"crypto/x509"
1616
"encoding/json"
17+
"fmt"
1718
"io/ioutil"
1819
"os"
1920
"strconv"
@@ -22,10 +23,10 @@ import (
2223
k8sresource "k8s.io/apimachinery/pkg/api/resource"
2324
"k8s.io/apimachinery/pkg/types"
2425

26+
rabbithole "github.com/michaelklishin/rabbit-hole/v2"
2527
. "github.com/onsi/ginkgo"
2628
. "github.com/onsi/gomega"
2729
. "github.com/onsi/gomega/gstruct"
28-
2930
rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
3031
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3132
"k8s.io/utils/pointer"
@@ -66,8 +67,7 @@ var _ = Describe("Operator", func() {
6667

6768
It("works", func() {
6869
By("publishing and consuming a message", func() {
69-
response, err := alivenessTest(hostname, port, username, password)
70-
Expect(err).NotTo(HaveOccurred())
70+
response := alivenessTest(hostname, port, username, password)
7171
Expect(response.Status).To(Equal("ok"))
7272
})
7373

@@ -377,9 +377,16 @@ CONSOLE_LOG=new`
377377
Expect(err).NotTo(HaveOccurred())
378378
assertHttpReady(hostname, port)
379379

380-
response, err := alivenessTest(hostname, port, username, password)
381-
Expect(err).NotTo(HaveOccurred())
380+
response := alivenessTest(hostname, port, username, password)
382381
Expect(response.Status).To(Equal("ok"))
382+
383+
// test https://github.com/rabbitmq/cluster-operator/issues/662 is fixed
384+
By("clustering correctly")
385+
rmqc, err := rabbithole.NewClient(fmt.Sprintf("http://%s:%s", hostname, port), username, password)
386+
Expect(err).NotTo(HaveOccurred())
387+
nodes, err := rmqc.ListNodes()
388+
Expect(err).NotTo(HaveOccurred())
389+
Expect(nodes).To(HaveLen(3))
383390
})
384391
})
385392
})
@@ -463,8 +470,7 @@ CONSOLE_LOG=new`
463470

464471
By("connecting to management API over TLS", func() {
465472
managementTLSNodePort := rabbitmqNodePort(ctx, clientSet, cluster, "management-tls")
466-
err := connectHTTPS(username, password, hostname, managementTLSNodePort, caFilePath)
467-
Expect(err).NotTo(HaveOccurred())
473+
Expect(connectHTTPS(username, password, hostname, managementTLSNodePort, caFilePath)).To(Succeed())
468474
})
469475

470476
By("talking MQTTS", func() {

system_tests/utils.go

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import (
5757
. "github.com/onsi/gomega"
5858
)
5959

60-
const podCreationTimeout = 600 * time.Second
60+
const podCreationTimeout = 10 * time.Minute
6161

6262
type featureFlag struct {
6363
Name string
@@ -363,40 +363,26 @@ func getMessageFromQueueAMQPS(username, password, hostname, amqpsPort, caFilePat
363363
return "", nil
364364
}
365365

366-
func alivenessTest(rabbitmqHostName, rabbitmqPort, rabbitmqUsername, rabbitmqPassword string) (*HealthcheckResponse, error) {
366+
func alivenessTest(rabbitmqHostName, rabbitmqPort, rabbitmqUsername, rabbitmqPassword string) *HealthcheckResponse {
367367
client := &http.Client{Timeout: 10 * time.Second}
368368
url := fmt.Sprintf("http://%s:%s/api/aliveness-test/%%2F", rabbitmqHostName, rabbitmqPort)
369369

370-
req, _ := http.NewRequest(http.MethodGet, url, nil)
370+
req, err := http.NewRequest(http.MethodGet, url, nil)
371+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
371372
req.SetBasicAuth(rabbitmqUsername, rabbitmqPassword)
372373

373374
resp, err := client.Do(req)
374-
if err != nil {
375-
fmt.Printf("Failed to run cluster aliveness test: %+v \n", err)
376-
return nil, fmt.Errorf("failed aliveness check: %v with api endpoint: %s", err, url)
377-
}
378-
379-
if resp.StatusCode != http.StatusOK {
380-
fmt.Printf("Cluster aliveness test failed. Status: %s \n", resp.Status)
381-
errMessage := fmt.Sprintf("Response code '%d' != '%d'", resp.StatusCode, http.StatusOK)
382-
return nil, fmt.Errorf("failed aliveness check: %v with api endpoint: %s, error msg: %s", err, url, errMessage)
383-
}
375+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
376+
Expect(resp).To(HaveHTTPStatus(http.StatusOK))
384377

385378
defer resp.Body.Close()
386379
b, err := ioutil.ReadAll(resp.Body)
387-
if err != nil {
388-
fmt.Printf("Failed to read cluster aliveness test: %s \n", err)
389-
return nil, fmt.Errorf("failed aliveness check: %v with api endpoint: %s", err, url)
390-
}
380+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
391381

392382
healthcheckResponse := &HealthcheckResponse{}
393-
err = json.Unmarshal(b, healthcheckResponse)
394-
if err != nil {
395-
fmt.Printf("Failed to umarshal cluster aliveness test result: %s \n", err)
396-
return nil, err
397-
}
383+
ExpectWithOffset(1, json.Unmarshal(b, healthcheckResponse)).To(Succeed())
398384

399-
return healthcheckResponse, nil
385+
return healthcheckResponse
400386
}
401387

402388
type HealthcheckResponse struct {

0 commit comments

Comments
 (0)