From 9fb0eb8f3674b80b086ca6f41d665630f9fe5d2f Mon Sep 17 00:00:00 2001 From: cheatfate Date: Mon, 6 Aug 2018 21:13:44 +0300 Subject: [PATCH] Fix #6. Add tests for #6. --- tests/testbugs.nim | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/testbugs.nim diff --git a/tests/testbugs.nim b/tests/testbugs.nim new file mode 100644 index 0000000..c6122e6 --- /dev/null +++ b/tests/testbugs.nim @@ -0,0 +1,42 @@ +# Asyncdispatch2 Test Suite +# (c) Copyright 2018 +# Status Research & Development GmbH +# +# Licensed under either of +# Apache License, version 2.0, (LICENSE-APACHEv2) +# MIT license (LICENSE-MIT) + +import unittest +import ../asyncdispatch2 + +const HELLO_PORT = 45679 +const TEST_MSG = "testmsg" +const MSG_LEN = TEST_MSG.len() + +type + CustomData = ref object + test: string + +proc udp4DataAvailable(transp: DatagramTransport, + remote: TransportAddress): Future[void] {.async, gcsafe.} = + var udata = getUserData[CustomData](transp) + if udata.test == "CHECK": + udata.test = "OK" + transp.close() + +proc issue6(): Future[bool] {.async.} = + var myself = initTAddress("127.0.0.1:" & $HELLO_PORT) + var data = CustomData() + data.test = "CHECK" + var dsock4 = newDatagramTransport(udp4DataAvailable, udata = data, + local = myself) + await dsock4.sendTo(myself, TEST_MSG, MSG_LEN) + await dsock4.join() + if data.test == "OK": + result = true + +when isMainModule: + suite "Asynchronous issues test suite": + test "Issue #6": + var res = waitFor(issue6()) + check res == true