Merge pull request #183 from vibe-d/test_macos

Test on macOS in addition to Linux/Windows.
This commit is contained in:
Leonid Kramer 2019-11-23 12:40:59 +01:00 committed by GitHub
commit b35756af7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 17 deletions

View file

@ -1,5 +1,9 @@
language: d
os:
- linux
- osx
d:
# order: latest DMD, oldest DMD, LDC/GDC, remaining DMD versions
# this way the overall test time gets cut down (GDC/LDC are a lot
@ -21,6 +25,7 @@ d:
env:
- CONFIG=select
- CONFIG=epoll
- CONFIG=kqueue
# disabled until the libasync driver of eventcore is more than a stub
#- CONFIG=libasync
@ -28,6 +33,22 @@ matrix:
allow_failures:
- env: CONFIG=libasync
- d: dmd-beta
exclude:
- os: linux
env: CONFIG=kqueue
- os: osx
env: CONFIG=epoll
# see https://github.com/ldc-developers/ldc/issues/2187
- d: ldc-1.17.0
os: osx
- d: ldc-1.16.0
os: osx
- d: ldc-1.15.0
os: osx
- d: ldc-1.14.0
os: osx
- d: ldc-1.9.0
os: osx
include:
- d: dmd
env: CONFIG='select' DUB_FLAGS='--build unittest-cov --build-mode=singleFile'

View file

@ -20,6 +20,11 @@ import std.typecons : No, Yes;
import core.exception : AssertError;
import core.time : msecs, seconds;
version (OSX) enum sleepTime = 3.seconds;
else enum sleepTime = 500.msecs;
void runTest()
{
auto dir = buildPath(tempDir, format("dirwatcher_test_%d", thisProcessID()));
@ -41,7 +46,7 @@ void runTest()
static DirectoryChange dc(Type t, string p) { return DirectoryChange(t, Path(p)); }
void check(DirectoryChange[] expected)
{
sleep(1500.msecs);
sleep(sleepTime);
assert(watcher.readChanges(changes, 100.msecs), "Could not read changes for " ~ expected.to!string);
assert(expected.all!((a)=> changes.canFind(a))(), "Change is not what was expected, got: " ~ changes.to!string ~ " but expected: " ~ expected.to!string);
assert(!watcher.readChanges(changes, 0.msecs), "Changes were returned when they shouldn't have, for " ~ expected.to!string);
@ -49,15 +54,15 @@ void runTest()
write(foo, null);
check([dc(Type.added, foo)]);
sleep(1500.msecs);
sleep(sleepTime);
write(foo, [0, 1]);
check([dc(Type.modified, foo)]);
remove(foo);
check([dc(Type.removed, foo)]);
write(foo, null);
sleep(1500.msecs);
sleep(sleepTime);
write(foo, [0, 1]);
sleep(1500.msecs);
sleep(sleepTime);
remove(foo);
check([dc(Type.added, foo), dc(Type.modified, foo), dc(Type.removed, foo)]);
@ -70,23 +75,23 @@ void runTest()
remove(bar);
watcher = Path(dir).watchDirectory(Yes.recursive);
write(foo, null);
sleep(1500.msecs);
sleep(sleepTime);
write(foo, [0, 1]);
sleep(1500.msecs);
sleep(sleepTime);
remove(foo);
write(bar, null);
sleep(1500.msecs);
sleep(sleepTime);
write(bar, [0, 1]);
sleep(1500.msecs);
sleep(sleepTime);
remove(bar);
check([dc(Type.added, foo), dc(Type.modified, foo), dc(Type.removed, foo),
dc(Type.added, bar), dc(Type.modified, bar), dc(Type.removed, bar)]);
write(foo, null);
sleep(1500.msecs);
sleep(sleepTime);
rename(foo, bar);
sleep(1500.msecs);
sleep(sleepTime);
remove(bar);
check([dc(Type.added, foo), dc(Type.removed, foo), dc(Type.added, bar), dc(Type.removed, bar)]);

View file

@ -19,15 +19,19 @@ void main()
auto initial = determineSocketCount();
foreach (i; 0 .. 3)
test();
assert(determineSocketCount() <= initial + 1, "Sockets leaked!");
}
void test()
{
TCPConnection conn;
try {
conn = connectTCP("127.0.0.1", 16565);
logError("Connection: %s", conn);
conn.close();
assert(false, "Didn't expect TCP connection on port 16565 to succeed");
} catch (Exception) { }
assert(determineSocketCount() == initial, "Sockets leaked!");
}
size_t determineSocketCount()

View file

@ -47,7 +47,9 @@ void main()
catch (Exception e) assert(false, "Receiver thread failed: "~e.msg);
logInfo("Receive loop finished.");
if (wc < 6*4-1) {
version (OSX) enum tolerance = 4; // macOS CI VMs have particularly bad timing behavior
else enum tolerance = 1;
if (wc < 6 * 4 - tolerance) {
logError("Receiver watchdog failure.");
exit(1);
}

View file

@ -26,8 +26,11 @@ void main()
assert(false, "Timeout did not occur.");
} catch (Exception e) {
auto duration = MonoTime.currTime() - start;
version (OSX) enum maxtolerance = 150.msecs;
else enum maxtolerance = 50.msecs;
assert(duration >= 99.msecs, "Timeout occurred too early");
assert(duration >= 99.msecs && duration < 150.msecs, "Timeout occurred too late.");
assert(duration >= 99.msecs && duration < 100.msecs + maxtolerance,
"Timeout occurred too late.");
logInfo("UDP receive timeout test was successful.");
exitEventLoop();
}

View file

@ -26,7 +26,7 @@ if [ ${BUILD_EXAMPLE=1} -eq 1 ]; then
fi
if [ ${RUN_TEST=1} -eq 1 ]; then
for ex in `\ls -1 tests/*.d`; do
script="${ex:0:-2}.sh"
script="${ex%.d}.sh"
if [ -e "$script" ]; then
echo "[INFO] Running test scipt $script"
(cd tests && "./${script:6}")