Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions system_tests/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strconv"
Expand All @@ -22,10 +23,10 @@ import (
k8sresource "k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/types"

rabbithole "github.com/michaelklishin/rabbit-hole/v2"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gstruct"

rabbitmqv1beta1 "github.com/rabbitmq/cluster-operator/api/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
Expand Down Expand Up @@ -66,8 +67,7 @@ var _ = Describe("Operator", func() {

It("works", func() {
By("publishing and consuming a message", func() {
response, err := alivenessTest(hostname, port, username, password)
Expect(err).NotTo(HaveOccurred())
response := alivenessTest(hostname, port, username, password)
Expect(response.Status).To(Equal("ok"))
})

Expand Down Expand Up @@ -377,9 +377,16 @@ CONSOLE_LOG=new`
Expect(err).NotTo(HaveOccurred())
assertHttpReady(hostname, port)

response, err := alivenessTest(hostname, port, username, password)
Expect(err).NotTo(HaveOccurred())
response := alivenessTest(hostname, port, username, password)
Expect(response.Status).To(Equal("ok"))

// test https://github.com/rabbitmq/cluster-operator/issues/662 is fixed
By("clustering correctly")
rmqc, err := rabbithole.NewClient(fmt.Sprintf("http://%s:%s", hostname, port), username, password)
Expect(err).NotTo(HaveOccurred())
nodes, err := rmqc.ListNodes()
Expect(err).NotTo(HaveOccurred())
Expect(nodes).To(HaveLen(3))
})
})
})
Expand Down Expand Up @@ -463,8 +470,7 @@ CONSOLE_LOG=new`

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

By("talking MQTTS", func() {
Expand Down
32 changes: 9 additions & 23 deletions system_tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import (
. "github.com/onsi/gomega"
)

const podCreationTimeout = 600 * time.Second
const podCreationTimeout = 10 * time.Minute

type featureFlag struct {
Name string
Expand Down Expand Up @@ -363,40 +363,26 @@ func getMessageFromQueueAMQPS(username, password, hostname, amqpsPort, caFilePat
return "", nil
}

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

req, _ := http.NewRequest(http.MethodGet, url, nil)
req, err := http.NewRequest(http.MethodGet, url, nil)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
req.SetBasicAuth(rabbitmqUsername, rabbitmqPassword)

resp, err := client.Do(req)
if err != nil {
fmt.Printf("Failed to run cluster aliveness test: %+v \n", err)
return nil, fmt.Errorf("failed aliveness check: %v with api endpoint: %s", err, url)
}

if resp.StatusCode != http.StatusOK {
fmt.Printf("Cluster aliveness test failed. Status: %s \n", resp.Status)
errMessage := fmt.Sprintf("Response code '%d' != '%d'", resp.StatusCode, http.StatusOK)
return nil, fmt.Errorf("failed aliveness check: %v with api endpoint: %s, error msg: %s", err, url, errMessage)
}
ExpectWithOffset(1, err).NotTo(HaveOccurred())
Expect(resp).To(HaveHTTPStatus(http.StatusOK))

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

healthcheckResponse := &HealthcheckResponse{}
err = json.Unmarshal(b, healthcheckResponse)
if err != nil {
fmt.Printf("Failed to umarshal cluster aliveness test result: %s \n", err)
return nil, err
}
ExpectWithOffset(1, json.Unmarshal(b, healthcheckResponse)).To(Succeed())

return healthcheckResponse, nil
return healthcheckResponse
}

type HealthcheckResponse struct {
Expand Down