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

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

@trondrift

Description

@trondrift

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions