diff --git a/cmd/cmd_test.go b/cmd/cmd_test.go index 6a25d3a..7fc8e45 100644 --- a/cmd/cmd_test.go +++ b/cmd/cmd_test.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" "testing" + "time" "github.com/prometheus/client_golang/prometheus/testutil" "github.com/rabbitmq/omq/pkg/metrics" @@ -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)) @@ -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) } } diff --git a/cmd/root.go b/cmd/root.go index 0190977..06de301 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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", @@ -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)