Skip to content

Commit

Permalink
Refactor: Remove redundant tests (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
DownerCase authored Feb 19, 2025
1 parent 47a73c0 commit 75535ba
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 79 deletions.
26 changes: 0 additions & 26 deletions ecal/publisher_protobuf_test.go

This file was deleted.

19 changes: 0 additions & 19 deletions ecal/publisher_string_test.go

This file was deleted.

37 changes: 20 additions & 17 deletions ecal/subscriber_protobuf_test.go → ecal/pubsub_protobuf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,22 @@ import (
"github.com/DownerCase/ecal-go/protos"
)

func TestSubscriber(t *testing.T) {
func TestProtobufSubscriberTimeout(t *testing.T) {
ecaltest.InitEcal(t)

defer ecal.Finalize() // Shutdown eCAL at the end of the program

sub := testutil.NewProtobufSubscriber[protos.Person](t, "testing_protobuf_subscriber_timeout")
defer sub.Delete()

msg, err := sub.Receive(50 * time.Millisecond)
if err == nil {
t.Error("Expected timeout, received message:", &msg)
}
}

func TestProtobufPubSub(t *testing.T) {
// Given: eCAL initialized, a protobuf publisher and a protobuf subscriber
ecaltest.InitEcal(t)

defer ecal.Finalize() // Shutdown eCAL at the end of the program
Expand All @@ -21,8 +36,10 @@ func TestSubscriber(t *testing.T) {
sub := testutil.NewProtobufSubscriber[protos.Person](t, "testing_protobuf_subscriber")
defer sub.Delete()

go sendMessages(pub)
// When: Publishing messages
go sendProtobufMessages(pub)

// Expect: To receive those messages
for range 10 {
msg, err := sub.Receive(2 * time.Second)
if err != nil {
Expand All @@ -47,21 +64,7 @@ func TestSubscriber(t *testing.T) {
}
}

func TestSubscriberTimeout(t *testing.T) {
ecaltest.InitEcal(t)

defer ecal.Finalize() // Shutdown eCAL at the end of the program

sub := testutil.NewProtobufSubscriber[protos.Person](t, "testing_protobuf_subscriber_timeout")
defer sub.Delete()

msg, err := sub.Receive(50 * time.Millisecond)
if err == nil {
t.Error("Expected timeout, received message:", &msg)
}
}

func sendMessages(p *ecal.ProtobufPublisher[*protos.Person]) {
func sendProtobufMessages(p *ecal.ProtobufPublisher[*protos.Person]) {
person := &protos.Person{
Id: 0, Name: "John", Email: "[email protected]",
Dog: &protos.Dog{Name: "Pluto"},
Expand Down
46 changes: 29 additions & 17 deletions ecal/subscriber_string_test.go → ecal/pubsub_string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,22 @@ import (

const TestMessage = "Test string"

func TestStringSubscriber(t *testing.T) {
func TestStringSubscriberTimeout(t *testing.T) {
ecaltest.InitEcal(t)

defer ecal.Finalize() // Shutdown eCAL at the end of the program

sub := testutil.NewStringSubscriber(t, "testing_string_subscriber_timeout")
defer sub.Delete()

msg, err := sub.Receive(50 * time.Millisecond)
if err == nil {
t.Error("Expected timeout, received message:", msg)
}
}

func TestStringPubSub(t *testing.T) {
// Given: eCAL initialized, a string publisher and a string subscriber
ecaltest.InitEcal(t)

defer ecal.Finalize() // Shutdown eCAL at the end of the program
Expand All @@ -23,8 +38,10 @@ func TestStringSubscriber(t *testing.T) {
sub := testutil.NewStringSubscriber(t, "testing_string_subscriber")
defer sub.Delete()

// When: Publishing messages
go sendStringMessages(pub)

// Expect: To receive those messages
for range 10 {
msg, err := sub.Receive(2 * time.Second)
if err != nil {
Expand All @@ -41,24 +58,19 @@ func TestStringSubscriber(t *testing.T) {
}
}

func TestStringSubscriberTimeout(t *testing.T) {
ecaltest.InitEcal(t)

defer ecal.Finalize() // Shutdown eCAL at the end of the program

sub := testutil.NewStringSubscriber(t, "testing_string_subscriber_timeout")
defer sub.Delete()

msg, err := sub.Receive(50 * time.Millisecond)
if err == nil {
t.Error("Expected timeout, received message:", msg)
}
}

func sendStringMessages(p *ecal.StringPublisher) {
// Alternate between using the channel directly and the function call
for !p.IsStopped() {
p.Messages <- TestMessage
if !p.IsStopped() {
p.Messages <- TestMessage

time.Sleep(10 * time.Millisecond)
time.Sleep(10 * time.Millisecond)
}

if !p.IsStopped() {
p.Send(TestMessage)

time.Sleep(10 * time.Millisecond)
}
}
}

0 comments on commit 75535ba

Please sign in to comment.