From eeab6ceeb9ea10f8cd91598f5814e740a3869ab0 Mon Sep 17 00:00:00 2001 From: Etienne Cimon Date: Wed, 13 Aug 2014 09:32:52 -0400 Subject: [PATCH] Added timeout non-zero verification - fixes #776 Quick fix Removed RedisDebug version for faster travis builds Remove debug artifacts --- source/vibe/db/redis/redis.d | 18 ++++++++++++------ tests/redis/dub.json | 2 +- tests/redis/source/app.d | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/source/vibe/db/redis/redis.d b/source/vibe/db/redis/redis.d index 7ec2cb46b3..0bb3f4d2c8 100644 --- a/source/vibe/db/redis/redis.d +++ b/source/vibe/db/redis/redis.d @@ -488,7 +488,9 @@ final class RedisSubscriber { bool bstop(){ if (!stop()) return false; - while (m_listening) sleep(1.msecs); + while (m_listening) { + sleep(1.msecs); + } return true; } @@ -496,6 +498,8 @@ final class RedisSubscriber { if (!m_listening) return false; m_stop = true; + // todo: publish some no-op data to wake up the listener? + return true; } @@ -567,7 +571,7 @@ final class RedisSubscriber { sw.start(); while (!gotData){ if (m_lockedConnection.conn.waitForData(5.seconds)) gotData = true; - if (sw.peek().seconds > timeout.total!"seconds") { gotData = false; break; } + if (timeout > 0.seconds && sw.peek().seconds > timeout.total!"seconds") { gotData = false; break; } if (m_stop){ gotData = false; break; } } sw.stop(); @@ -592,10 +596,10 @@ final class RedisSubscriber { auto ln = cast(string)m_lockedConnection.conn.readLine(); string cmd; - if (ln[0] == "$"[0]){ + if (ln[0] == '$'){ cmd = cast(string)m_lockedConnection.conn.readLine(); } - else if (ln[0] == "*"[0]) { + else if (ln[0] == '*') { cmd = getString(); }else { enforceEx!RedisProtocolException(false, "expected $ or *"); @@ -676,8 +680,10 @@ final class RedisSubscriber { auto task = runTask({ blisten(callback, timeout); }); - import std.datetime; - while(!m_listening) sleep(1.usecs); + import std.datetime : usecs; + while (!m_listening) { + sleep(1.usecs); + } return task; } } diff --git a/tests/redis/dub.json b/tests/redis/dub.json index 777057cd96..830243faa5 100644 --- a/tests/redis/dub.json +++ b/tests/redis/dub.json @@ -4,5 +4,5 @@ "dependencies": { "vibe-d": {"version": "~master", "path": "../../"} }, - "versions": ["VibeCustomMain", "RedisDebug"] + "versions": ["VibeCustomMain"] } diff --git a/tests/redis/source/app.d b/tests/redis/source/app.d index 71679b1f57..5d07badd97 100644 --- a/tests/redis/source/app.d +++ b/tests/redis/source/app.d @@ -67,8 +67,8 @@ void runTest() logInfo("LISTEN Recv Channel: %s, Message: %s", channel.to!string, msg.to!string); logInfo("LISTEN Recv Time: %s", Clock.currTime().toString()); }); - assert(sub.isListening); + sleep(1.seconds); sub.subscribe("SomeChannel"); logInfo("PUBLISH Sent: %s", Clock.currTime().toString()); @@ -84,7 +84,7 @@ void runTest() int main() { - int ret = 0; + int ret = 0; runTask({ try runTest(); catch (Throwable th) {