Skip to content
This repository has been archived by the owner on Apr 6, 2019. It is now read-only.

Seeing inconsistent test results in TEST(RedisSubscriber, SubscribeMultiplePublished) #85

Closed
trondrift opened this issue Jun 30, 2017 · 4 comments

Comments

@trondrift
Copy link

trondrift commented Jun 30, 2017

I've been developing a proof of concept windows app using cpp_redis for pubsub and noticed my subscriber doesn't always catch consecutive publishes to its channel. I can re-create this behavior using the provided unit tests. If I vary the number of publish calls in the SubscribeMultiplePublished test, it seems to fail sometimes, but not others.

This is the test code I've been using:

 TEST(RedisSubscriber, SubscribeMultiplePublished) {
  cpp_redis::redis_subscriber sub;
  cpp_redis::redis_client client;
  std::condition_variable cv;

  sub.connect();
  client.connect();

  std::atomic<int> number_times_called = ATOMIC_VAR_INIT(0);
  sub.subscribe("/chan",
    [&](const std::string& channel, const std::string& message) {
      ++number_times_called;
      EXPECT_TRUE(channel == "/chan");
      if (number_times_called == 1)
        EXPECT_TRUE(message == "first");
      else if (number_times_called == 2)
        EXPECT_TRUE(message == "second");
      else if (number_times_called == 3)
	EXPECT_TRUE(message == "third");
      else if (number_times_called == 4)
	EXPECT_TRUE(message == "fourth");
      else if (number_times_called == 5)
	EXPECT_TRUE(message == "fifth");

      cv.notify_all();
    },
    [&](int64_t) {
      client.publish("/chan", "first");
      client.publish("/chan", "second");
      client.publish("/chan", "third");
      client.publish("/chan", "fourth");
      client.publish("/chan", "fifth");
      client.commit();
    });

  sub.commit();

  std::mutex mutex;
  std::unique_lock<std::mutex> lock(mutex);
  cv.wait_for(lock, std::chrono::seconds(60), [&]() -> bool { return number_times_called == 5; });

  EXPECT_TRUE(number_times_called == 5);
}

TEST RESULTS

My setup uses 64-bit Windows 7, Visual Studio 2015 (The project however is built 32-bit). I see this both building cpp_redis statically as well as dynamically.

@trondrift trondrift changed the title Seeing Inconsistent Test Results in TEST(RedisSubscriber, SubscribeMultiplePublished) Seeing inconsistent test results in TEST(RedisSubscriber, SubscribeMultiplePublished) Jun 30, 2017
@Cylix
Copy link
Owner

Cylix commented Jul 2, 2017

Hi,

I was not able to reproduce this bug on my macbook.
However, there is a high change that this issue is related to tacopie#17.

Can you just confirm me which version of cpp_redis are you using?
My guess is that you are using the latest version and that this bug is not happening in earlier versions?

If it is the case, then this issue is indeed related to tacopie#17 and a fix will be submitted by tomorrow night.

Thanks for reporting this issue!

Best

@Cylix
Copy link
Owner

Cylix commented Jul 2, 2017

I published a fix in v3.5.3.
I closed this issue but feel free to re-open it if the bug is still there or if you have any other issues to report!

Best

@trondrift
Copy link
Author

trondrift commented Jul 10, 2017 via email

@Cylix
Copy link
Owner

Cylix commented Jul 10, 2017

Awesome, thank you for your feedback!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants