forked from nim-lang/Nim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix nim-lang#14320 (tasyncawait.nim is recently very flaky) + avoid h…
…ardcoding service ports everywhere + flakyAssert (nim-lang#14327) * hotfix nim-lang#14320 tasyncawait.nim is recently very flaky * fix nim-lang#14327 * add flakyAssert
- Loading branch information
1 parent
d9e80bf
commit 81304e2
Showing
10 changed files
with
102 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This directory contains helper files used by several tests, to avoid | ||
code duplication, akin to a std extension tailored for testament. | ||
|
||
Some of these could later migrate to stdlib. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import std/[nativesockets, asyncdispatch, os] | ||
|
||
proc bindAvailablePort*(handle: SocketHandle, port = Port(0)): Port = | ||
block: | ||
var name: Sockaddr_in | ||
name.sin_family = typeof(name.sin_family)(toInt(AF_INET)) | ||
name.sin_port = htons(uint16(port)) | ||
name.sin_addr.s_addr = htonl(INADDR_ANY) | ||
if bindAddr(handle, cast[ptr SockAddr](addr(name)), | ||
sizeof(name).Socklen) < 0'i32: | ||
raiseOSError(osLastError()) | ||
result = getLocalAddr(handle, AF_INET)[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import std/private/miscdollars | ||
|
||
template flakyAssert*(cond: untyped, msg = "", notifySuccess = true) = | ||
## API to deal with flaky or failing tests. This avoids disabling entire tests | ||
## altogether so that at least the parts that are working are kept being | ||
## tested. This also avoids making CI fail periodically for tests known to | ||
## be flaky. Finally, for known failures, passing `notifySuccess = true` will | ||
## log that the test succeeded, which may indicate that a bug was fixed | ||
## "by accident" and should be looked into. | ||
const info = instantiationInfo(-1, true) | ||
const expr = astToStr(cond) | ||
if cond and not notifySuccess: | ||
discard # silent success | ||
else: | ||
var msg2 = "" | ||
toLocation(msg2, info.filename, info.line, info.column) | ||
if cond: | ||
# a flaky test is failing, we still report it but we don't fail CI | ||
msg2.add " FLAKY_SUCCESS " | ||
else: | ||
# a previously failing test is now passing, a pre-existing bug might've been | ||
# fixed by accidend | ||
msg2.add " FLAKY_FAILURE " | ||
msg2.add $expr & " " & msg | ||
echo msg2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
discard """ | ||
output: "Finished" | ||
""" | ||
|
||
import asyncdispatch, asyncnet | ||
|
||
proc createServer(port: Port) {.async.} = | ||
var port: Port | ||
proc createServer() {.async.} = | ||
var server = newAsyncSocket() | ||
server.setSockOpt(OptReuseAddr, true) | ||
bindAddr(server, port) | ||
bindAddr(server) | ||
port = getLocalAddr(server)[1] | ||
server.listen() | ||
while true: | ||
let client = await server.accept() | ||
discard await client.recvLine() | ||
|
||
asyncCheck createServer(10335.Port) | ||
asyncCheck createServer() | ||
|
||
var done = false | ||
proc f(): Future[void] {.async.} = | ||
let s = newAsyncNativeSocket() | ||
await s.connect("localhost", 10335.Port) | ||
let s = createAsyncNativeSocket() | ||
await s.connect("localhost", port) | ||
await s.send("123") | ||
echo "Finished" | ||
done = true | ||
|
||
waitFor f() | ||
doAssert done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters