Skip to content

Commit

Permalink
Fix tests after rebasing v2
Browse files Browse the repository at this point in the history
Signed-off-by: Aitor Perez Cedres <[email protected]>
  • Loading branch information
Zerpet committed Nov 17, 2023
1 parent e8a753d commit 57bf7bc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pkg/raw/client_dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ var _ = Describe("ClientDial", func() {
<-time.After(time.Millisecond * 100) // have to introduce artificial delay for the background frame handler

conf, _ := raw.NewClientConfiguration("")
conf.SetDial(func(_, _ string) (net.Conn, error) {
conf.Dial = func(_, _ string) (net.Conn, error) {
c, err := net.DialTimeout("unix", serverSocketPath, time.Second)
if err != nil {
panic(err)
}
<-waiter
go fakeServer.fakeRabbitMQConnectionOpen(ctx)
return c, err
})
}

c, err := raw.DialConfig(ctx, conf)
Expect(err).ToNot(HaveOccurred())
Expand Down
2 changes: 1 addition & 1 deletion pkg/raw/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ var _ = Describe("Client", func() {
Should(BeTrue(), "expected connection to be open")

By("recording the server properties")
Expect(conf.RabbitmqBroker().ServerProperties).To(HaveKeyWithValue("product", "mock-rabbitmq"))
Expect(conf.RabbitmqAddr.ServerProperties).To(HaveKeyWithValue("product", "mock-rabbitmq"))

By("closing the client connection gracefully")
go fakeRabbitMQ.fakeRabbitMQConnectionClose(itCtx)
Expand Down
7 changes: 6 additions & 1 deletion pkg/stream/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,12 @@ var _ = Describe("Environment", func() {
Return(errors.New("something went wrong"))
})

It("logs the error and moves on", func() {
It("logs the error and moves on", Pending, func() {
// TODO: the locator has its own logger, it does not use the logger
// from the context. This tests seems to make no sense, as the
// locator is appended by an utility function for tests, and
// this tests assumes that the locator uses the logger from context,
// which is not true. Revisit this test and its assumptions.
logBuffer := gbytes.NewBuffer()
logger := slog.New(slog.NewTextHandler(logBuffer, nil))
ctx := raw.NewContextWithLogger(context.Background(), *logger)
Expand Down
11 changes: 6 additions & 5 deletions pkg/stream/producer_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,21 @@ var _ = Describe("ProducerManager", func() {
Expect(p.(*standardProducer).rawClient).To(Equal(pm.client))
Expect(p.(*standardProducer).rawClientMu).To(Equal(pm.clientM))
Expect(p.(*standardProducer).publisherId).To(BeEquivalentTo(0))
Expect(pm.producers).To(HaveLen(1))
Expect(pm.producers).To(ContainElement(p))

p2, err := pm.createProducer(context.Background(), &ProducerOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(p2.(*standardProducer).rawClient).To(Equal(pm.client))
Expect(p2.(*standardProducer).rawClientMu).To(Equal(pm.clientM))
Expect(p2.(*standardProducer).publisherId).To(BeEquivalentTo(1))
Expect(pm.producers).To(ContainElement(p2))

p3, err := pm.createProducer(context.Background(), &ProducerOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(p3.(*standardProducer).rawClient).To(Equal(pm.client))
Expect(p3.(*standardProducer).rawClientMu).To(Equal(pm.clientM))
Expect(p3.(*standardProducer).publisherId).To(BeEquivalentTo(2))
Expect(pm.producers).To(HaveLen(3))
Expect(pm.producers).To(ContainElement(p3))
})

When("manager is full", func() {
Expand Down Expand Up @@ -119,7 +120,7 @@ var _ = Describe("ProducerManager", func() {
Expect(p3.(*standardProducer).publisherId).To(BeEquivalentTo(1))

By("reusing the producer slot #1")
Expect(pm.producers).To(HaveLen(2)) // this ensures we have not appended to the slice
Expect(pm.producers[1]).ToNot(BeNil())

By("reusing publisher ID 2", func() {
pm.producers = append(
Expand All @@ -134,8 +135,8 @@ var _ = Describe("ProducerManager", func() {
Expect(err).ToNot(HaveOccurred())
Expect(p4.(*standardProducer).publisherId).To(BeEquivalentTo(2))

By("reusing the producer slot #1")
Expect(pm.producers).To(HaveLen(5))
By("reusing the producer slot #2")
Expect(pm.producers[2]).ToNot(BeNil())
})
})

Expand Down
3 changes: 3 additions & 0 deletions pkg/stream/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"github.com/rabbitmq/rabbitmq-stream-go-client/v2/pkg/raw"
"log/slog"
"sync"
"time"
)

Expand Down Expand Up @@ -36,6 +37,8 @@ func (e *Environment) AppendLocatorRawClient(c raw.Clienter) {
retryPolicy: func(int) time.Duration {
return time.Millisecond * 10
},
destructor: &sync.Once{},
done: make(chan struct{}),
})
}

Expand Down

0 comments on commit 57bf7bc

Please sign in to comment.