diff --git a/.github/workflows/openssl.yml b/.github/workflows/openssl.yml index 182c2d2c3f..2433f0a2cd 100644 --- a/.github/workflows/openssl.yml +++ b/.github/workflows/openssl.yml @@ -110,3 +110,10 @@ jobs: exit 1 fi dub --skip-registry=all test vibe-d:tls + + - name: '[POSIX] Run tests' + env: + VIBED_DRIVER: vibe-core + PARTS: builds,unittests,examples,tests + run: | + ./run-ci.sh diff --git a/examples/bench-mongodb/dub.json b/examples/bench-mongodb/dub.json deleted file mode 100644 index 53358195c2..0000000000 --- a/examples/bench-mongodb/dub.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "bench-urlrouter", - "description": "Benchmark for the URLRouter class", - "dependencies": { - "vibe-d:mongodb": {"path": "../../"} - }, - "versions": [ "VibeRouterTreeMatch" ] -} diff --git a/examples/bench-mongodb/source/app.d b/examples/bench-mongodb/source/app.d deleted file mode 100644 index f4c23930cb..0000000000 --- a/examples/bench-mongodb/source/app.d +++ /dev/null @@ -1,51 +0,0 @@ -import vibe.core.log; -import vibe.db.mongo.mongo; -import std.datetime.stopwatch; -import std.string : format; - - -Duration runTimed(scope void delegate() del) -{ - StopWatch sw; - sw.start(); - del(); - sw.stop(); - return sw.peek; -} - -void main() -{ - enum nqueries = 100_000; - - struct Item { - BsonObjectID _id; - int i; - double d; - //string s; - } - - auto db = connectMongoDB("localhost").getDatabase("test"); - auto coll = db["benchmark"]; - coll.remove(); - foreach (i; 0 .. 10) { - Item itm; - itm._id = BsonObjectID.generate(); - itm.i = i; - itm.d = i * 1.3; - //itm.s = "Hello, World!"; - coll.insert(itm); - } - - logInfo("Running queries..."); - auto dur_query = runTimed({ - struct Q { int i; } - foreach (i; 0 .. nqueries) { - auto res = coll.find!Item(Q(5)); - res.front; - //logInfo("%s %s", res.front.d, res.front.s); - res.popFront(); - } - }); - - logInfo(" %s queries: %s", nqueries, dur_query); -} diff --git a/examples/mongodb/dub.json b/examples/mongodb/dub.json deleted file mode 100644 index aa827fba0b..0000000000 --- a/examples/mongodb/dub.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "mongodb-example", - "description": "Basic MongoDB usage example.", - "dependencies": { - "vibe-d:mongodb": {"path": "../../"} - } -} diff --git a/examples/mongodb/source/app.d b/examples/mongodb/source/app.d deleted file mode 100644 index abb853c38d..0000000000 --- a/examples/mongodb/source/app.d +++ /dev/null @@ -1,19 +0,0 @@ -import vibe.core.log; -import vibe.db.mongo.mongo; - -import std.array; - -void main() -{ - logInfo("Connecting to DB..."); - auto db = connectMongoDB("localhost").getDatabase("test"); - auto coll = db["test"]; - - logInfo("Querying DB..."); - Bson query = Bson(["name" : Bson("hans")]); - auto result = coll.find(query); - - logInfo("Iterating results..."); - foreach (i, doc; result.byPair) - logInfo("Item %d: %s", i, doc.toJson().toString()); -} diff --git a/examples/redis-pubsub/dub.json b/examples/redis-pubsub/dub.json deleted file mode 100644 index e0259f5d58..0000000000 --- a/examples/redis-pubsub/dub.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "redis-pubsub-example", - "description": "Basic Redis Pub/Sub usage example.", - "dependencies": { - "vibe-d:redis": {"path": "../../"} - } -} diff --git a/examples/redis-pubsub/source/app.d b/examples/redis-pubsub/source/app.d deleted file mode 100644 index 3e3af24610..0000000000 --- a/examples/redis-pubsub/source/app.d +++ /dev/null @@ -1,35 +0,0 @@ -module app; - -import vibe.core.core; -import vibe.core.log; -import vibe.db.redis.redis; - -import std.functional; - -import core.time; - -void printReply(string channel, string message) @safe -{ - logInfo("Received a message from channel %s: %s", channel, message); -} - -RedisSubscriber subscriber; - -int main(string[] args) -{ - auto publisher = new RedisClient(); - subscriber = publisher.createSubscriber(); - - subscriber.subscribe("test1", "test2"); - auto task = subscriber.listen(toDelegate(&printReply)); - publisher.getDatabase(0).publish("test1", "Hello World!"); - publisher.getDatabase(0).publish("test2", "Hello from Channel 2"); - - auto taskHandler = runTask({ - subscriber.subscribe("test-fiber"); - publisher.getDatabase(0).publish("test-fiber", "Hello from the Fiber!"); - subscriber.unsubscribe(); - }); - - return runApplication(&args); -} diff --git a/examples/redis/dub.json b/examples/redis/dub.json deleted file mode 100644 index 34c7b717fa..0000000000 --- a/examples/redis/dub.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "redis-example", - "description": "Basic Redis usage example.", - "dependencies": { - "vibe-d:redis": {"path": "../../"} - } -} diff --git a/examples/redis/source/app.d b/examples/redis/source/app.d deleted file mode 100644 index b1bdaaa8f8..0000000000 --- a/examples/redis/source/app.d +++ /dev/null @@ -1,9 +0,0 @@ -import vibe.core.log; -import vibe.db.redis.redis; - -void main() -{ - auto redis = new RedisClient(); - redis.getDatabase(0).setBit("test", 15, true); - logInfo("Result: %s", redis.getDatabase(0).getBit("test", 15)); -} diff --git a/tests/redis/dub.json b/tests/redis/dub.json deleted file mode 100644 index aca05a93b4..0000000000 --- a/tests/redis/dub.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "tests", - "description": "High level Redis test for vibe.d", - "dependencies": { - "vibe-d:redis": {"path": "../../"} - } -} diff --git a/tests/redis/source/app.d b/tests/redis/source/app.d deleted file mode 100644 index cf33fac1f5..0000000000 --- a/tests/redis/source/app.d +++ /dev/null @@ -1,178 +0,0 @@ -/// Requires redis service running on localhost with default port - -module app; - -import vibe.core.core; -import vibe.core.log; -import vibe.db.redis.redis; -import core.time; -import std.array : array; -import std.algorithm : sort, equal; -import std.exception : assertThrown; -import std.typecons : tuple; - -void runTest() -{ - //setLogLevel(LogLevel.trace); - /* open a redis server locally to run these tests - * Windows download link: https://github.com/MSOpenTech/redis/releases - * Linux: use "yum install redis" on RHEL or "apt-get install redis" on Debian-like - */ - RedisClient redis; - try redis = new RedisClient(); - catch (Exception) { - logInfo("Failed to connect to local Redis server. Skipping test."); - return; - } - - scope(exit) redis.releaseUnusedConnections(); - - { - auto db = redis.getDatabase(0); - db.deleteAll(); - - assert(db.setNX("setNXTest","foo", 30.seconds)); - assert(!db.setNX("setNXTest","foo", 30.seconds)); - assert(db.setNX("setNXTest2","foo")); - assert(!db.setNX("setNXTest2","foo")); - assert(db.setXX("setNXTest2","foo")); - assert(!db.setXX("setXXTestNegative","foo")); - - db.setEX("test1", 1000, "test1"); - db.setEX("test2", 1000, "test2"); - db.setEX("test3", 1000, "test3"); - db.setEX("test4", 1000, "test4"); - db.setEX("test5", 1000, "test5"); - db.setEX("test6", 1000, "test6"); - db.setEX("test7", 1000, "test7"); - db.setEX("test8", 1000, "test8"); - db.setEX("test9", 1000, "test9"); - db.setEX("test10", 1000, "0"); - assert(db.get("test1") == "test1"); - assert(db.get("test2") == "test2"); - assert(db.get("test3") == "test3"); - assert(db.get("test4") == "test4"); - assert(db.get("test5") == "test5"); - assert(db.get("test6") == "test6"); - assert(db.get("test7") == "test7"); - assert(db.get("test8") == "test8"); - assert(db.get("test9") == "test9"); - assert(db.get("test10") == "0"); - - db.del("saddTests"); - db.sadd("saddTests", "item1"); - db.sadd("saddTests", "item2"); - assert(sort(db.smembers("saddTests").array).equal(["item1", "item2"])); - - db.zadd("zaddTests", 0.5, "a", 1.0, "b", 2.0, "c", 1.5, "d"); - assert(db.zrangeByScore("zaddTests", 0.5, 1.5).equal(["a", "b", "d"])); - assert(db.zrangeByScore!(string, "()")("zaddTests", 0.5, 1.5).equal(["b"])); - assert(db.zrangeByScore!(string, "[)")("zaddTests", 0.5, 1.5).equal(["a", "b"])); - assert(db.zrangeByScore!(string, "(]")("zaddTests", 0.5, 1.5).equal(["b", "d"])); - - db.append("test1", "test1append"); - db.append("test2", "test2append"); - assert(db.get!string("test1") == "test1test1append"); - assert(db.get!string("test2") == "test2test2append"); - - db.incr("test10"); - assert(db.get!long("test10") == 1); - - db.del("test1", "test2","test3","test4","test5","test6","test7","test8","test9","test10"); - db.del("saddTests", "zaddTests"); - - db.srem("test1", "test1append"); - db.srem("test2", "test2append"); - - assert(db.smembers("test1").empty); - assert(db.smembers("test2").empty); - assert(!db.smembers("test1").hasNext()); - - // test blpop - assert(db.blpop("nonexistent", 1).isNull()); - db.lpush("test_list", "foo"); - assert(db.blpop("test_list", 1).get() == tuple("test_list", "foo")); - db.del("test_list"); - } - - testLocking(redis.getDatabase(0)); - - RedisSubscriber sub; - { - RedisSubscriber scoped = redis.createSubscriber(); - sub = scoped; - sleep(50.msecs); - } - import std.datetime; - - assert(!sub.isListening); - sub.listen((string channel, string msg){ - logInfo("LISTEN Recv Channel: %s, Message: %s", channel, msg); - logInfo("LISTEN Recv Time: %s", Clock.currTime()); - }); - assert(sub.isListening); - sub.subscribe("SomeChannel"); - sub.subscribe("SomeChannel"); - sub.subscribe("SomeChannel"); - sleep(100.msecs); - - redis.getDatabase(0).publish("SomeChannel", "Messageeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"); - - logInfo("PUBLISH Sent: %s", Clock.currTime()); - sleep(100.msecs); - - sub.unsubscribe("SomeChannel"); - sub.unsubscribe("SomeChannel"); - sub.unsubscribe("SomeChannel"); - sub.bstop(); - logInfo("LISTEN Stopped"); - assert(!sub.isListening); - redis.getDatabase(0).publish("SomeChannel", "Messageeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"); - - assertThrown(redis.getDatabase(0).eval("foo!!!", null)); - assert(redis.getDatabase(0).get("test1") == ""); - - logInfo("Redis Test Succeeded."); -} - -void testLocking(RedisDatabase _db) -{ - logInfo("run lock test..."); - - import vibe.db.redis.idioms; - - auto lock = RedisLock(_db,"lock_key"); - - auto testMethod = { - foreach(i; 0..100) - { - lock.performLocked({ - assert(_db.setNX("lockedWriteTest","foo")); - assert(1 == _db.del("lockedWriteTest")); - }); - } - }; - - auto t1 = runTask(testMethod); - auto t2 = runTask(testMethod); - - t1.join(); - t2.join(); - - logInfo("lock test finished"); -} - -int main() -{ - int ret = 0; - runTask({ - try runTest(); - catch (Throwable th) { - logError("Test failed: %s", th.msg); - logDiagnostic("Full error: %s", th); - ret = 1; - } finally exitEventLoop(true); - }); - runEventLoop(); - return ret; -}