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 language: d
os:
- linux
- osx
d: d:
# order: latest DMD, oldest DMD, LDC/GDC, remaining DMD versions # order: latest DMD, oldest DMD, LDC/GDC, remaining DMD versions
# this way the overall test time gets cut down (GDC/LDC are a lot # this way the overall test time gets cut down (GDC/LDC are a lot
@ -21,6 +25,7 @@ d:
env: env:
- CONFIG=select - CONFIG=select
- CONFIG=epoll - CONFIG=epoll
- CONFIG=kqueue
# disabled until the libasync driver of eventcore is more than a stub # disabled until the libasync driver of eventcore is more than a stub
#- CONFIG=libasync #- CONFIG=libasync
@ -28,6 +33,22 @@ matrix:
allow_failures: allow_failures:
- env: CONFIG=libasync - env: CONFIG=libasync
- d: dmd-beta - 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: include:
- d: dmd - d: dmd
env: CONFIG='select' DUB_FLAGS='--build unittest-cov --build-mode=singleFile' 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.exception : AssertError;
import core.time : msecs, seconds; import core.time : msecs, seconds;
version (OSX) enum sleepTime = 3.seconds;
else enum sleepTime = 500.msecs;
void runTest() void runTest()
{ {
auto dir = buildPath(tempDir, format("dirwatcher_test_%d", thisProcessID())); 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)); } static DirectoryChange dc(Type t, string p) { return DirectoryChange(t, Path(p)); }
void check(DirectoryChange[] expected) void check(DirectoryChange[] expected)
{ {
sleep(1500.msecs); sleep(sleepTime);
assert(watcher.readChanges(changes, 100.msecs), "Could not read changes for " ~ expected.to!string); 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(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); 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); write(foo, null);
check([dc(Type.added, foo)]); check([dc(Type.added, foo)]);
sleep(1500.msecs); sleep(sleepTime);
write(foo, [0, 1]); write(foo, [0, 1]);
check([dc(Type.modified, foo)]); check([dc(Type.modified, foo)]);
remove(foo); remove(foo);
check([dc(Type.removed, foo)]); check([dc(Type.removed, foo)]);
write(foo, null); write(foo, null);
sleep(1500.msecs); sleep(sleepTime);
write(foo, [0, 1]); write(foo, [0, 1]);
sleep(1500.msecs); sleep(sleepTime);
remove(foo); remove(foo);
check([dc(Type.added, foo), dc(Type.modified, foo), dc(Type.removed, foo)]); check([dc(Type.added, foo), dc(Type.modified, foo), dc(Type.removed, foo)]);
@ -70,23 +75,23 @@ void runTest()
remove(bar); remove(bar);
watcher = Path(dir).watchDirectory(Yes.recursive); watcher = Path(dir).watchDirectory(Yes.recursive);
write(foo, null); write(foo, null);
sleep(1500.msecs); sleep(sleepTime);
write(foo, [0, 1]); write(foo, [0, 1]);
sleep(1500.msecs); sleep(sleepTime);
remove(foo); remove(foo);
write(bar, null); write(bar, null);
sleep(1500.msecs); sleep(sleepTime);
write(bar, [0, 1]); write(bar, [0, 1]);
sleep(1500.msecs); sleep(sleepTime);
remove(bar); remove(bar);
check([dc(Type.added, foo), dc(Type.modified, foo), dc(Type.removed, foo), 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)]); dc(Type.added, bar), dc(Type.modified, bar), dc(Type.removed, bar)]);
write(foo, null); write(foo, null);
sleep(1500.msecs); sleep(sleepTime);
rename(foo, bar); rename(foo, bar);
sleep(1500.msecs); sleep(sleepTime);
remove(bar); remove(bar);
check([dc(Type.added, foo), dc(Type.removed, foo), dc(Type.added, bar), dc(Type.removed, 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(); auto initial = determineSocketCount();
foreach (i; 0 .. 3)
test();
assert(determineSocketCount() <= initial + 1, "Sockets leaked!");
}
void test()
{
TCPConnection conn; TCPConnection conn;
try { try {
conn = connectTCP("127.0.0.1", 16565); 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"); assert(false, "Didn't expect TCP connection on port 16565 to succeed");
} catch (Exception) { } } catch (Exception) { }
assert(determineSocketCount() == initial, "Sockets leaked!");
} }
size_t determineSocketCount() size_t determineSocketCount()

View file

@ -47,7 +47,9 @@ void main()
catch (Exception e) assert(false, "Receiver thread failed: "~e.msg); catch (Exception e) assert(false, "Receiver thread failed: "~e.msg);
logInfo("Receive loop finished."); 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."); logError("Receiver watchdog failure.");
exit(1); exit(1);
} }

View file

@ -26,8 +26,11 @@ void main()
assert(false, "Timeout did not occur."); assert(false, "Timeout did not occur.");
} catch (Exception e) { } catch (Exception e) {
auto duration = MonoTime.currTime() - start; 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, "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."); logInfo("UDP receive timeout test was successful.");
exitEventLoop(); exitEventLoop();
} }

View file

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