Skip to content

Commit

Permalink
Updated based on feedback
Browse files Browse the repository at this point in the history
- Fix typo in error message.
- Remove redundant sleep.
- Use Fatalf to stop the test early.
- Use prexisting unknown message in v2/binding/test.

Signed-off-by: Matthew Dowdell <matthew.dowdell@hpe.com>
  • Loading branch information
Matthew Dowdell authored and embano1 committed Aug 3, 2023
1 parent 310da90 commit f84be73
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions v2/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/google/go-cmp/cmp"

"github.com/cloudevents/sdk-go/v2/binding"
"github.com/cloudevents/sdk-go/v2/binding/test"
"github.com/cloudevents/sdk-go/v2/client"
"github.com/cloudevents/sdk-go/v2/event"
"github.com/cloudevents/sdk-go/v2/protocol"
Expand Down Expand Up @@ -431,25 +432,22 @@ func TestClientStartReceiverWithAckMalformedEvent(t *testing.T) {

c, err := client.New(receiver, tc.opts...)
if err != nil {
t.Errorf("failed to construct client: %v", err)
t.Fatalf("failed to construct client: %v", err)
}

go c.StartReceiver(ctx, func(ctx context.Context, e event.Event) protocol.Result {
t.Error("receiver callback called unexpectedly")
return nil
})

// wait for receive to occur
time.Sleep(time.Millisecond)

ctx, cancelTimeout := context.WithTimeout(ctx, time.Second)
defer cancelTimeout()

select {
case <-receiver.finished:
// continue to rest of the test
case <-ctx.Done():
t.Errorf("timeoued out waiting for receiver to complete")
t.Fatalf("timed out waiting for receiver to complete")
}

if tc.expectedAck {
Expand Down Expand Up @@ -555,18 +553,6 @@ func isImportantHeader(h string) bool {
return true
}

type mockMessage struct{}

func (m *mockMessage) ReadEncoding() binding.Encoding {
return binding.EncodingUnknown
}

func (m *mockMessage) ReadStructured(ctx context.Context, writer binding.StructuredWriter) error {
return nil
}
func (m *mockMessage) ReadBinary(ctx context.Context, writer binding.BinaryWriter) error { return nil }
func (m *mockMessage) Finish(err error) error { return nil }

type mockReceiver struct {
mu sync.Mutex
count int
Expand All @@ -584,7 +570,7 @@ func (m *mockReceiver) Receive(ctx context.Context) (binding.Message, error) {

m.count++

return binding.WithFinish(&mockMessage{}, func(err error) {
return binding.WithFinish(test.UnknownMessage, func(err error) {
m.result = err
close(m.finished)
}), nil
Expand Down

0 comments on commit f84be73

Please sign in to comment.