Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mkuratczyk committed Oct 2, 2023
1 parent 52ff325 commit fb57c57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"
"testing"
"time"

"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/rabbitmq/omq/pkg/metrics"
Expand Down Expand Up @@ -52,7 +53,7 @@ func TestPublishConsume(t *testing.T) {
consumeProtoLabel = tc.consume
}
rootCmd := RootCmd()
args := []string{tc.publish + "-" + tc.consume, "-z", "3s", "-C", "1", "-D", "1", "-q", tc.publish + tc.consume}
args := []string{tc.publish + "-" + tc.consume, "-C", "1", "-D", "1", "-q", tc.publish + tc.consume}
rootCmd.SetArgs(args)
fmt.Println("Running test: omq", strings.Join(args, " "))
publishedBefore := testutil.ToFloat64(metrics.MessagesPublished.WithLabelValues(publishProtoLabel))
Expand All @@ -61,7 +62,12 @@ func TestPublishConsume(t *testing.T) {
err := rootCmd.Execute()

assert.Nil(t, err)
assert.Equal(t, publishedBefore+1, testutil.ToFloat64(metrics.MessagesPublished.WithLabelValues(publishProtoLabel)))
assert.Equal(t, consumedBefore+1, testutil.ToFloat64(metrics.MessagesConsumed.WithLabelValues(consumeProtoLabel)))
assert.Eventually(t, func() bool {
return testutil.ToFloat64(metrics.MessagesPublished.WithLabelValues(publishProtoLabel)) == publishedBefore+1

}, 10*time.Second, 100*time.Millisecond)
assert.Eventually(t, func() bool {
return testutil.ToFloat64(metrics.MessagesConsumed.WithLabelValues(consumeProtoLabel)) == consumedBefore+1
}, 10*time.Second, 100*time.Millisecond)
}
}
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func RootCmd() *cobra.Command {
},
}
amqp_amqp.Flags().IntVarP(&cfg.Amqp.ConsumerCredits, "amqp-consumer-credits", "", 1, "AMQP 1.0 consumer credits")
amqp_amqp.Flags().VarP(enumflag.New(&cfg.QueueDurability, "queue-durability", config.AmqpDurabilityModes, enumflag.EnumCaseInsensitive), "queue-durability", "", "Queue durability (default: configuration - the queue definition is durable)")

amqp_stomp = &cobra.Command{
Use: "amqp-stomp",
Expand Down Expand Up @@ -140,6 +139,7 @@ func RootCmd() *cobra.Command {
rootCmd.PersistentFlags().IntVarP(&cfg.Rate, "rate", "r", -1, "Messages per second (0 = unlimited)")
rootCmd.PersistentFlags().DurationVarP(&cfg.Duration, "duration", "z", 0, "Duration (eg. 10s, 5m, 2h)")
rootCmd.PersistentFlags().BoolVarP(&cfg.UseMillis, "use-millis", "m", false, "Use milliseconds for timestamps")
rootCmd.PersistentFlags().VarP(enumflag.New(&cfg.QueueDurability, "queue-durability", config.AmqpDurabilityModes, enumflag.EnumCaseInsensitive), "queue-durability", "", "Queue durability (default: configuration - the queue definition is durable)")

rootCmd.AddCommand(amqp_amqp)
rootCmd.AddCommand(amqp_stomp)
Expand Down

0 comments on commit fb57c57

Please sign in to comment.