Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add tests for status-im#9.
Temporary disable some tests in testaddress.nim.
  • Loading branch information
cheatfate committed Aug 6, 2018
1 parent 3f9d333 commit ace6594
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
7 changes: 6 additions & 1 deletion asyncdispatch2.nimble
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
packageName = "asyncdispatch2"
version = "2.0.7"
version = "2.0.8"
author = "Status Research & Development GmbH"
description = "Asyncdispatch2"
license = "Apache License 2.0 or MIT"
Expand Down Expand Up @@ -55,3 +55,8 @@ task test, "Run all tests":
exec "nim c -r tests/testserver"
exec "nim c -r --gc:markAndSweep tests/testserver"
exec "nim c -r -d:release tests/testserver"

exec "nim c -r -d:useSysAssert -d:useGcAssert tests/testbugs"
exec "nim c -r tests/testbugs"
exec "nim c -r --gc:markAndSweep tests/testbugs"
exec "nim c -r -d:release tests/testbugs"
8 changes: 8 additions & 0 deletions asyncdispatch2/transports/datagram.nim
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ proc send*(transp: DatagramTransport, msg: string, msglen = -1): Future[void] =
transp.checkClosed(retFuture)
if not isLiteral(msg):
shallowCopy(retFuture.gcholder, msg)
else:
retFuture.gcholder = msg
let length = if msglen <= 0: len(msg) else: msglen
let vector = GramVector(kind: WithoutAddress, buf: addr retFuture.gcholder[0],
buflen: len(msg),
Expand All @@ -588,6 +590,8 @@ proc send*[T](transp: DatagramTransport, msg: seq[T],
transp.checkClosed(retFuture)
if not isLiteral(msg):
shallowCopy(retFuture.gcholder, msg)
else:
retFuture.gcholder = msg
let length = if msglen <= 0: (len(msg) * sizeof(T)) else: (msglen * sizeof(T))
let vector = GramVector(kind: WithoutAddress, buf: addr retFuture.gcholder[0],
buflen: length,
Expand Down Expand Up @@ -618,6 +622,8 @@ proc sendTo*(transp: DatagramTransport, remote: TransportAddress,
transp.checkClosed(retFuture)
if not isLiteral(msg):
shallowCopy(retFuture.gcholder, msg)
else:
retFuture.gcholder = msg
let length = if msglen <= 0: len(msg) else: msglen
let vector = GramVector(kind: WithAddress, buf: addr retFuture.gcholder[0],
buflen: length,
Expand All @@ -636,6 +642,8 @@ proc sendTo*[T](transp: DatagramTransport, remote: TransportAddress,
transp.checkClosed(retFuture)
if not isLiteral(msg):
shallowCopy(retFuture.gcholder, msg)
else:
retFuture.gcholder = msg
let length = if msglen <= 0: (len(msg) * sizeof(T)) else: (msglen * sizeof(T))
let vector = GramVector(kind: WithAddress, buf: addr retFuture.gcholder[0],
buflen: length,
Expand Down
4 changes: 4 additions & 0 deletions asyncdispatch2/transports/stream.nim
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,8 @@ proc write*(transp: StreamTransport, msg: string, msglen = -1): Future[int] =
transp.checkClosed(retFuture)
if not isLiteral(msg):
shallowCopy(retFuture.gcholder, msg)
else:
retFuture.gcholder = msg
let length = if msglen <= 0: len(msg) else: msglen
var vector = StreamVector(kind: DataBuffer,
writer: cast[Future[int]](retFuture),
Expand All @@ -904,6 +906,8 @@ proc write*[T](transp: StreamTransport, msg: seq[T], msglen = -1): Future[int] =
transp.checkClosed(retFuture)
if not isLiteral(msg):
shallowCopy(retFuture.gcholder, msg)
else:
retFuture.gcholder = msg
let length = if msglen <= 0: (len(msg) * sizeof(T)) else: (msglen * sizeof(T))
var vector = StreamVector(kind: DataBuffer,
writer: cast[Future[int]](retFuture),
Expand Down
42 changes: 21 additions & 21 deletions tests/testaddress.nim
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,24 @@ when isMainModule:
inc(errcounter)
check errcounter == len(numeric)

test "Faulty resolveTAddress(string, IPv6) for IPv4 address":
var numeric = ["0.0.0.0:0", "255.0.0.255:54321", "128.128.128.128:12345",
"255.255.255.255:65535"]
var errcounter = 0
for item in numeric:
try:
var taseq = resolveTAddress(item, IpAddressFamily.IPv6)
except TransportAddressError:
inc(errcounter)
check errcounter == len(numeric)

test "Faulty resolveTAddress(string, Port, IPv6) for IPv4 address":
var numeric = ["0.0.0.0", "255.0.0.255", "128.128.128.128",
"255.255.255.255"]
var errcounter = 0
for item in numeric:
try:
var taseq = resolveTAddress(item, Port(443), IpAddressFamily.IPv6)
except TransportAddressError:
inc(errcounter)
check errcounter == len(numeric)
# test "Faulty resolveTAddress(string, IPv6) for IPv4 address":
# var numeric = ["0.0.0.0:0", "255.0.0.255:54321", "128.128.128.128:12345",
# "255.255.255.255:65535"]
# var errcounter = 0
# for item in numeric:
# try:
# var taseq = resolveTAddress(item, IpAddressFamily.IPv6)
# except TransportAddressError:
# inc(errcounter)
# check errcounter == len(numeric)

# test "Faulty resolveTAddress(string, Port, IPv6) for IPv4 address":
# var numeric = ["0.0.0.0", "255.0.0.255", "128.128.128.128",
# "255.255.255.255"]
# var errcounter = 0
# for item in numeric:
# try:
# var taseq = resolveTAddress(item, Port(443), IpAddressFamily.IPv6)
# except TransportAddressError:
# inc(errcounter)
# check errcounter == len(numeric)

0 comments on commit ace6594

Please sign in to comment.