From 0f430ec3391abdc14505bcb9cf7e7197839fa3ea Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 10 Dec 2017 17:58:44 -0500 Subject: [PATCH 01/21] test suite: refactor TestServer_clientID --- testsuite/classlibrary/TestServerClientID.sc | 107 ++++++++++++------- 1 file changed, 70 insertions(+), 37 deletions(-) diff --git a/testsuite/classlibrary/TestServerClientID.sc b/testsuite/classlibrary/TestServerClientID.sc index 10302639eaf..082e5165c39 100644 --- a/testsuite/classlibrary/TestServerClientID.sc +++ b/testsuite/classlibrary/TestServerClientID.sc @@ -17,80 +17,113 @@ the tests should also include irregular numbers for maxLogins, e.g. 1, 2, 3, 5, */ TestServer_clientID : UnitTest { - // these while server is off - test_clientIDChecks { - var s = Server(\test_clientIDChecks); - this.assert(s.clientID == 0, "s.clientID should be 0 by default."); - // test checks for bad input - s.clientID = -1.sqrt; - this.assert(s.clientID == 0, "s.clientID should block non-Integers."); - s.clientID = -123; - this.assert(s.clientID == 0, "s.clientID should block negative numbers."); - s.options.maxLogins = 32; - s.clientID = s.options.maxLogins; - this.assert(s.clientID == 0, "s.clientID should block number >= maxLogins."); - s.clientID = s.options.maxLogins - 1; - this.assert(s.clientID == 31, "s.clientID should be settable if valid."); - s.remove; + + var server; + + setUp { + server = Server(this.class.name); + } + + tearDown { + server.remove; + } + + test_default { + this.assert(server.clientID == 0, "s.clientID should be 0 by default."); + } + + test_badInputTypes { + server.clientID = -1.sqrt; + this.assert(server.clientID == 0, "s.clientID should block NaN."); + server.clientID = -123; + this.assert(server.clientID == 0, "s.clientID should block negative numbers."); + server.clientID = 0.57; + this.assert(server.clientID == 0, "s.clientID should block floating point numbers."); + } + + test_tooHigh { + server.options.maxLogins = 32; + server.clientID = server.options.maxLogins; + this.assert(server.clientID == 0, "s.clientID should block number >= maxLogins."); + } + + test_validRange { + server.options.maxLogins = 32; + server.clientID = server.options.maxLogins - 1; + this.assert(server.clientID == 31, "s.clientID should be settable if valid."); } - test_userSpecifiedClientID { + test_userSpecifiedClientID_invalid { var options = ServerOptions.new; - var s = Server(\test_userSpecifiedClientID, nil, options, 1); + var s = Server(thisMethod.name, nil, options, 1); this.assert(s.clientID.isNil, "Making a server with invalid clientID should return a server with clientID nil."); - options.maxLogins_(8); - s.remove; - s = Server(\test_userSpecifiedClientID, nil, options, 7); + s.remove + } + + test_userSpecifiedClientID_valid { + var options = ServerOptions().maxLogins_(8); + var s = Server(thisMethod.name, nil, options, 7); this.assert(s.clientID == 7, "Making a server with valid nonzero clientID should work."); s.remove; } - test_allocatorRanges { - var s = Server(\test_allocatorRanges); + test_allocatorRanges_singleClient { + // remember the pre-test allocator var prevClass = Server.nodeAllocClass; Server.nodeAllocClass = NodeIDAllocator; - s.options.maxLogins = 1; - s.newAllocators; + server.options.maxLogins = 1; + server.newAllocators; this.assert( - s.nodeAllocator.numIDs == (2 ** 26), - "nodeAllocator should have its normal range." + server.nodeAllocator.numIDs == (2 ** 26), + "for a single client, nodeAllocator should have its normal range." ); this.assert( - s.audioBusAllocator.size == (s.options.numAudioBusChannels - s.options.firstPrivateBus), + server.audioBusAllocator.size == (server.options.numAudioBusChannels - server.options.firstPrivateBus), "for a single client, audioBusAllocator should have full range minus hardware channels." ); this.assert( - s.controlBusAllocator.size == s.options.numControlBusChannels, + server.controlBusAllocator.size == server.options.numControlBusChannels, "for a single client, controlBusAllocator should have full range." ); this.assert( - s.bufferAllocator.size == s.options.numBuffers, + server.bufferAllocator.size == server.options.numBuffers, "for a single client, bufferAllocator should have full range." ); - s.options.maxLogins = 16; - s.newAllocators; + // reset pre-test allocator + Server.nodeAllocClass = prevClass; + } + + test_allocatorRanges_multiClient { + // remember the pre-test allocator + var prevClass = Server.nodeAllocClass; + Server.nodeAllocClass = NodeIDAllocator; + server.options.maxLogins = 16; + server.newAllocators; + + this.assert( + server.nodeAllocator.numIDs == (2 ** 26), + "for 16 clients, nodeAllocator should have its normal range." + ); this.assert( - s.audioBusAllocator.size == - (s.options.numAudioBusChannels - s.options.firstPrivateBus div: 16), + server.audioBusAllocator.size == + (server.options.numAudioBusChannels - server.options.firstPrivateBus div: 16), "for 16 clients, controlBusAllocator should divide private bus range evenly." ); this.assert( - s.controlBusAllocator.size == (s.options.numControlBusChannels div: 16), + server.controlBusAllocator.size == (server.options.numControlBusChannels div: 16), "for 16 clients, controlBusAllocator should divide private bus range evenly." ); this.assert( - s.bufferAllocator.size == (s.options.numBuffers div: 16), + server.bufferAllocator.size == (server.options.numBuffers div: 16), "for 16 clients, bufferAllocator should divide range evenly." ); Server.nodeAllocClass = prevClass; - s.remove; - } } From 04a36af8c331370cd4134df96b5171a19efa9ff9 Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 10 Dec 2017 18:16:21 -0500 Subject: [PATCH 02/21] test suite: prefer assertEquals --- testsuite/classlibrary/TestServerClientID.sc | 50 ++++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/testsuite/classlibrary/TestServerClientID.sc b/testsuite/classlibrary/TestServerClientID.sc index 082e5165c39..2fea8ca0521 100644 --- a/testsuite/classlibrary/TestServerClientID.sc +++ b/testsuite/classlibrary/TestServerClientID.sc @@ -29,28 +29,28 @@ TestServer_clientID : UnitTest { } test_default { - this.assert(server.clientID == 0, "s.clientID should be 0 by default."); + this.assertEquals(server.clientID, 0, "s.clientID should be 0 by default."); } test_badInputTypes { server.clientID = -1.sqrt; - this.assert(server.clientID == 0, "s.clientID should block NaN."); + this.assertEquals(server.clientID, 0, "s.clientID should block NaN."); server.clientID = -123; - this.assert(server.clientID == 0, "s.clientID should block negative numbers."); + this.assertEquals(server.clientID, 0, "s.clientID should block negative numbers."); server.clientID = 0.57; - this.assert(server.clientID == 0, "s.clientID should block floating point numbers."); + this.assertEquals(server.clientID, 0, "s.clientID should block floating point numbers."); } test_tooHigh { server.options.maxLogins = 32; server.clientID = server.options.maxLogins; - this.assert(server.clientID == 0, "s.clientID should block number >= maxLogins."); + this.assertEquals(server.clientID, 0, "s.clientID should block number >= maxLogins."); } test_validRange { server.options.maxLogins = 32; server.clientID = server.options.maxLogins - 1; - this.assert(server.clientID == 31, "s.clientID should be settable if valid."); + this.assertEquals(server.clientID, 31, "s.clientID should be settable if valid."); } test_userSpecifiedClientID_invalid { @@ -63,7 +63,7 @@ TestServer_clientID : UnitTest { test_userSpecifiedClientID_valid { var options = ServerOptions().maxLogins_(8); var s = Server(thisMethod.name, nil, options, 7); - this.assert(s.clientID == 7, "Making a server with valid nonzero clientID should work."); + this.assertEquals(s.clientID, 7, "Making a server with valid nonzero clientID should work."); s.remove; } @@ -75,21 +75,21 @@ TestServer_clientID : UnitTest { server.options.maxLogins = 1; server.newAllocators; - this.assert( - server.nodeAllocator.numIDs == (2 ** 26), + this.assertEquals( + server.nodeAllocator.numIDs, 2 ** 26, "for a single client, nodeAllocator should have its normal range." ); - this.assert( - server.audioBusAllocator.size == (server.options.numAudioBusChannels - server.options.firstPrivateBus), + this.assertEquals( + server.audioBusAllocator.size, server.options.numAudioBusChannels - server.options.firstPrivateBus, "for a single client, audioBusAllocator should have full range minus hardware channels." ); - this.assert( - server.controlBusAllocator.size == server.options.numControlBusChannels, + this.assertEquals( + server.controlBusAllocator.size, server.options.numControlBusChannels, "for a single client, controlBusAllocator should have full range." ); - this.assert( - server.bufferAllocator.size == server.options.numBuffers, + this.assertEquals( + server.bufferAllocator.size, server.options.numBuffers, "for a single client, bufferAllocator should have full range." ); @@ -105,22 +105,22 @@ TestServer_clientID : UnitTest { server.options.maxLogins = 16; server.newAllocators; - this.assert( - server.nodeAllocator.numIDs == (2 ** 26), + this.assertEquals( + server.nodeAllocator.numIDs, 2 ** 26, "for 16 clients, nodeAllocator should have its normal range." ); - this.assert( - server.audioBusAllocator.size == - (server.options.numAudioBusChannels - server.options.firstPrivateBus div: 16), - "for 16 clients, controlBusAllocator should divide private bus range evenly." + this.assertEquals( + server.audioBusAllocator.size, + (server.options.numAudioBusChannels - server.options.firstPrivateBus) div: 16, + "for 16 clients, controlBusAllocator should divide non-hardware channels evenly." ); - this.assert( - server.controlBusAllocator.size == (server.options.numControlBusChannels div: 16), + this.assertEquals( + server.controlBusAllocator.size, server.options.numControlBusChannels div: 16, "for 16 clients, controlBusAllocator should divide private bus range evenly." ); - this.assert( - server.bufferAllocator.size == (server.options.numBuffers div: 16), + this.assertEquals( + server.bufferAllocator.size, server.options.numBuffers div: 16, "for 16 clients, bufferAllocator should divide range evenly." ); From 93648d5780692ed4f63deeabb3c202fe8d3dd7c9 Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 10 Dec 2017 18:33:35 -0500 Subject: [PATCH 03/21] test suite: refactor TestServer_clientID_booted --- .../classlibrary/TestServer_clientIDBooted.sc | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/testsuite/classlibrary/TestServer_clientIDBooted.sc b/testsuite/classlibrary/TestServer_clientIDBooted.sc index acc04139716..0fc08b6dc58 100644 --- a/testsuite/classlibrary/TestServer_clientIDBooted.sc +++ b/testsuite/classlibrary/TestServer_clientIDBooted.sc @@ -3,68 +3,68 @@ TestServer_clientID_booted.run; */ +// with running server TestServer_clientID_booted : UnitTest { - // with running server - test_clientIDResetByServer { - var options = ServerOptions.new; - var s = Server(\test_clientIDResetByServer, NetAddr("localhost", 57111), options); + test_default { + var s = Server(this.class.name); + this.bootServer(s); + this.assertEquals(s.clientID, 0, "clientID should be 0 by default"); + s.quit; + s.remove; + } - s.options.maxLogins = 4; + test_setWithSetter { + var options = ServerOptions.new.maxLogins_(4); + var s = Server(this.class.name, nil, options); s.clientID = 3; + this.bootServer(s); - s.sync; - 1.wait; - this.assert(s.clientID == 3, "clientID should be settable before booting."); + this.assertEquals(s.clientID, 3, "clientID should be settable by clientID_ before boot."); s.quit; s.remove; + } - 1.wait; - - s = Server(\test_clientIDResetByServer2, NetAddr("localhost", 57112), options, 3); + test_setWithConstructor { + var options = ServerOptions.new.maxLogins_(4); + var s = Server(this.class.name, nil, options, 3); this.bootServer(s); - s.sync; - 1.wait; - this.assert(s.clientID == 3, "clientID should remain as is when booting a server."); + this.assertEquals(s.clientID, 3, "clientID should be settable by Server constructor."); s.quit; s.remove; } + // TODO: find a better home for this test test_nodeIDAlloc_ServerTree { - var s = Server(\test_clientIDResetByServer3, NetAddr("localhost", 57113)); + var s = Server(this.class.name); var synth1, synth2; var func = { synth1 = Synth("default"); }; - ServerTree.add( func, s ); + ServerTree.add(func, s); this.bootServer(s); synth2 = Synth("default", [\freq, 330]); this.assert(synth1.nodeID != synth2.nodeID, "first nodeID after booting should not repeat nodeID created in ServerTree."); - 0.5.wait; synth1.free; synth2.free; s.quit; - ServerTree.remove( func, s ); + ServerTree.remove(func, s); s.remove; } - test_clientIDLockedWhileRunning { + test_lockedWhileRunning { var options = ServerOptions.new.maxLogins_(4); - var s = Server( - \test_clientIDLockedWhileRunning, - NetAddr("localhost", 57114), - options, - clientID: 1); + var s = Server(this.class.name, nil, options, 1); var lockedID; this.bootServer(s); lockedID = s.clientID; s.clientID = 3; - this.assert(s.clientID == lockedID, + this.assertEquals(s.clientID, lockedID, "clientID should be locked while server is running."); s.quit; From 8f710de543a4aca30d589d4e6310a5a221e5e69a Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 10 Dec 2017 18:35:23 -0500 Subject: [PATCH 04/21] test suite: rename TestServer_clientID_booted.sc --- ...TestServer_clientIDBooted.sc => TestServer_clientID_booted.sc} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename testsuite/classlibrary/{TestServer_clientIDBooted.sc => TestServer_clientID_booted.sc} (100%) diff --git a/testsuite/classlibrary/TestServer_clientIDBooted.sc b/testsuite/classlibrary/TestServer_clientID_booted.sc similarity index 100% rename from testsuite/classlibrary/TestServer_clientIDBooted.sc rename to testsuite/classlibrary/TestServer_clientID_booted.sc From 28e484188584e40bdf5ec68144010a615c640880 Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 10 Dec 2017 18:35:49 -0500 Subject: [PATCH 05/21] test suite: rename TestServer_clientID.sc To match name of contained class --- .../{TestServerClientID.sc => TestServer_clientID.sc} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename testsuite/classlibrary/{TestServerClientID.sc => TestServer_clientID.sc} (100%) diff --git a/testsuite/classlibrary/TestServerClientID.sc b/testsuite/classlibrary/TestServer_clientID.sc similarity index 100% rename from testsuite/classlibrary/TestServerClientID.sc rename to testsuite/classlibrary/TestServer_clientID.sc From 0ab5dc85b6e2f41f7d9e279ca6b34196d0bba09e Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 10 Dec 2017 18:39:02 -0500 Subject: [PATCH 06/21] test suite: remove unnecessary fork in method --- testsuite/classlibrary/TestServer_boot.sc | 42 +++++++++++------------ 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/testsuite/classlibrary/TestServer_boot.sc b/testsuite/classlibrary/TestServer_boot.sc index 80b796dde51..efab1bc0130 100644 --- a/testsuite/classlibrary/TestServer_boot.sc +++ b/testsuite/classlibrary/TestServer_boot.sc @@ -1,27 +1,25 @@ TestServer_boot : UnitTest { - test_Volume { - fork { - var s = Server(\test_Volume, NetAddr("localhost", 57111)); - var queryReply; - var correctReply = [ '/g_queryTree.reply', 0, 0, 2, 1, 0, 1000, -1, 'volumeAmpControl2' ]; - - // set volume so its synthdef, synth and set get sent right after boot - s.volume.volume = -1; - s.bootSync; - - OSCFunc({ |msg| - queryReply = msg; - },'/g_queryTree.reply', s.addr).oneShot; - s.sendMsg("/g_queryTree", 0); - s.sync; - - this.assert(queryReply == correctReply, - "Server boot should send volume synthdef and create synth immediately when set to nonzero volume."); - 0.1.wait; - - s.quit.remove; - } + test_volume { + var s = Server(\test_Volume, NetAddr("localhost", 57111)); + var queryReply; + var correctReply = [ '/g_queryTree.reply', 0, 0, 2, 1, 0, 1000, -1, 'volumeAmpControl2' ]; + + // set volume so its synthdef, synth and set get sent right after boot + s.volume.volume = -1; + s.bootSync; + + OSCFunc({ |msg| + queryReply = msg; + },'/g_queryTree.reply', s.addr).oneShot; + s.sendMsg("/g_queryTree", 0); + s.sync; + + this.assert(queryReply == correctReply, + "Server boot should send volume synthdef and create synth immediately when set to nonzero volume."); + 0.1.wait; + + s.quit.remove; } test_waitForBoot { From 243c40554aa5a1735be14128f3cc5b4a466d25f5 Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 10 Dec 2017 18:41:15 -0500 Subject: [PATCH 07/21] test suite: remove unnecessary wait --- testsuite/classlibrary/TestServer_boot.sc | 1 - 1 file changed, 1 deletion(-) diff --git a/testsuite/classlibrary/TestServer_boot.sc b/testsuite/classlibrary/TestServer_boot.sc index efab1bc0130..c9152571eb3 100644 --- a/testsuite/classlibrary/TestServer_boot.sc +++ b/testsuite/classlibrary/TestServer_boot.sc @@ -17,7 +17,6 @@ TestServer_boot : UnitTest { this.assert(queryReply == correctReply, "Server boot should send volume synthdef and create synth immediately when set to nonzero volume."); - 0.1.wait; s.quit.remove; } From 3557e5d2a2f0327664f09d5d2bdf30e92d3d5d16 Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 10 Dec 2017 19:12:43 -0500 Subject: [PATCH 08/21] test suite: factor out setUp, tearDown --- testsuite/classlibrary/TestServer_boot.sc | 29 +++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/testsuite/classlibrary/TestServer_boot.sc b/testsuite/classlibrary/TestServer_boot.sc index c9152571eb3..698e20d42be 100644 --- a/testsuite/classlibrary/TestServer_boot.sc +++ b/testsuite/classlibrary/TestServer_boot.sc @@ -1,7 +1,17 @@ TestServer_boot : UnitTest { + var s; // mock server for testing + + setUp { + s = Server(this.class.name, nil, ServerOptions()); + } + + tearDown { + 0.5.wait; + s.remove; + } + test_volume { - var s = Server(\test_Volume, NetAddr("localhost", 57111)); var queryReply; var correctReply = [ '/g_queryTree.reply', 0, 0, 2, 1, 0, 1000, -1, 'volumeAmpControl2' ]; @@ -18,12 +28,10 @@ TestServer_boot : UnitTest { this.assert(queryReply == correctReply, "Server boot should send volume synthdef and create synth immediately when set to nonzero volume."); - s.quit.remove; + s.quit; } test_waitForBoot { - var options = ServerOptions.new; - var s = Server(\test_waitForBoot, NetAddr("localhost", 57112), options); var vals = List[]; var of = OSCFunc({ |msg| vals.add(msg[3]) }, \tr, s.addr); var cond = Condition(); @@ -43,12 +51,10 @@ TestServer_boot : UnitTest { ); of.free; - s.quit.remove; + s.quit; } test_bootSync { - var options = ServerOptions.new; - var s = Server(\test_bootSync, NetAddr("localhost", 57113), options); var vals = List[]; var of = OSCFunc({ |msg| vals.add(msg[3]) }, \tr, s.addr); var synth; @@ -64,11 +70,11 @@ TestServer_boot : UnitTest { ); of.free; - s.quit.remove; + s.quit; } test_allocWhileBooting { - var s = Server(\test_allocWhileBooting), done = false, count = 0; + var done = false, count = 0; var prevNodeID = -1, nodeID = 0, failed = false; var timer = fork { 5.wait; @@ -101,12 +107,10 @@ TestServer_boot : UnitTest { this.assert(failed.not, "allocating nodeIDs while booting should not produce duplicate nodeIDs." ); - s.quit.remove; + s.quit; } test_fourWaysToPlaySound { - var options = ServerOptions.new; - var s = Server(\test_fourWaysToPlaySound, NetAddr("localhost", 57114), options); var amps, flags; var o = OSCFunc({ |msg| amps = msg.drop(3) }, '/the8Amps'); var cond = Condition(); @@ -152,7 +156,6 @@ TestServer_boot : UnitTest { ); Ndef.dictFor(s).clear; - s.remove; o.free; } } From 44fe81bf219b270147497813e12e31bd952a7609 Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 10 Dec 2017 19:13:06 -0500 Subject: [PATCH 09/21] test suite: rewrite test_allocWhileBooting --- testsuite/classlibrary/TestServer_boot.sc | 41 ++++++++--------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/testsuite/classlibrary/TestServer_boot.sc b/testsuite/classlibrary/TestServer_boot.sc index 698e20d42be..c803beb626e 100644 --- a/testsuite/classlibrary/TestServer_boot.sc +++ b/testsuite/classlibrary/TestServer_boot.sc @@ -74,35 +74,22 @@ TestServer_boot : UnitTest { } test_allocWhileBooting { - var done = false, count = 0; - var prevNodeID = -1, nodeID = 0, failed = false; - var timer = fork { - 5.wait; - failed = true; - "% - server boot timed out.".format(thisMethod).warn; - }; - - s.boot; - - while { - count < 1000 and: { failed.not } - } { - if(s.serverRunning) { - ".".post; - count = count + 1; - nodeID = s.nextNodeID; - if(nodeID <= prevNodeID) { - failed = true; - "failed: prevNodeID % and nodeID = % " - .format(prevNodeID, nodeID).warn; - }; - prevNodeID = nodeID; + var prevNodeID = -1; + var nodeID = 0; + var failed = false; + + this.bootServer(s); + + 1000.do { + ".".post; + nodeID = s.nextNodeID; + if(nodeID <= prevNodeID) { + failed = true; + "failed: prevNodeID % and nodeID = %" + .format(prevNodeID, nodeID).warn; }; - 0.001.wait; + prevNodeID = nodeID; }; - "end of while loop, timer stops...".postln; - - timer.stop; this.assert(failed.not, "allocating nodeIDs while booting should not produce duplicate nodeIDs." From ce8580e71add45320e5e8d85acbf20a19277128f Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 10 Dec 2017 19:13:17 -0500 Subject: [PATCH 10/21] test suite: rewrite test_fourWaysToPlaySound --- testsuite/classlibrary/TestServer_boot.sc | 45 +++++++++++------------ 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/testsuite/classlibrary/TestServer_boot.sc b/testsuite/classlibrary/TestServer_boot.sc index c803beb626e..692c73e8c99 100644 --- a/testsuite/classlibrary/TestServer_boot.sc +++ b/testsuite/classlibrary/TestServer_boot.sc @@ -98,35 +98,34 @@ TestServer_boot : UnitTest { } test_fourWaysToPlaySound { - var amps, flags; + var amps = []; + var flags; var o = OSCFunc({ |msg| amps = msg.drop(3) }, '/the8Amps'); var cond = Condition(); + var pbindPlayer; s.options.numOutputBusChannels = 8; - s.waitForBoot({ - var amps = List[]; - - // 4 ways to make sounds on the first 8 chans - Pbind(\legato, 1.1, \server, s).play; - { Saw.ar([220, 330], 0.1) }.play(s, 2); - Synth(\default, [\out, 4], s); - Ndef(\testX -> s.name, { PinkNoise.ar(0.1) ! 2 }).play(6); - // get 8 sound levels - { - SendReply.kr( - Impulse.kr(10), '/the8Amps', - Amplitude.kr(InFeedback.ar(0, 8), 0.001, 1), - ) - }.play(s); - - 2.wait; - - s.quit; - cond.unhang; - }); + this.bootServer(s); - cond.hang; + // 4 ways to make sounds on the first 8 chans + pbindPlayer = Pbind(\legato, 1.1, \server, s).play; + { Saw.ar([220, 330], 0.1) }.play(s, 2); + Synth(\default, [\out, 4], s); + Ndef(\testX -> s.name, { PinkNoise.ar(0.1) ! 2 }).play(6); + // get 8 sound levels + { + SendReply.kr( + Impulse.kr(10), '/the8Amps', + Amplitude.kr(InFeedback.ar(0, 8), 0.001, 1), + ) + }.play(s); + + s.sync; + 2.wait; + + pbindPlayer.stop; + s.quit; flags = amps.clump(2).collect(_.every(_ > 0.01)).postln; this.assert(flags[0], From b163d41a0a1e66c6ca3b6d42d73e63326bb94282 Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 10 Dec 2017 21:23:50 -0500 Subject: [PATCH 11/21] test suite: clear Ndef dict before quitting server in test_fourWaysToPlaySound --- testsuite/classlibrary/TestServer_boot.sc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/classlibrary/TestServer_boot.sc b/testsuite/classlibrary/TestServer_boot.sc index 692c73e8c99..73d3765ce6e 100644 --- a/testsuite/classlibrary/TestServer_boot.sc +++ b/testsuite/classlibrary/TestServer_boot.sc @@ -125,6 +125,7 @@ TestServer_boot : UnitTest { 2.wait; pbindPlayer.stop; + Ndef.dictFor(s).clear; s.quit; flags = amps.clump(2).collect(_.every(_ > 0.01)).postln; @@ -141,7 +142,6 @@ TestServer_boot : UnitTest { "Server: Ndef should play right after booting." ); - Ndef.dictFor(s).clear; o.free; } } From 5cf38421730f6d71a42572d2c7d479ab95b0bd95 Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 10 Dec 2017 21:26:08 -0500 Subject: [PATCH 12/21] test suite: loosen test Sometimes reports false failures if testing > 0.01 Change to != 0 to make the test a little stricter --- testsuite/classlibrary/TestServer_boot.sc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/classlibrary/TestServer_boot.sc b/testsuite/classlibrary/TestServer_boot.sc index 73d3765ce6e..62007e8961a 100644 --- a/testsuite/classlibrary/TestServer_boot.sc +++ b/testsuite/classlibrary/TestServer_boot.sc @@ -128,7 +128,7 @@ TestServer_boot : UnitTest { Ndef.dictFor(s).clear; s.quit; - flags = amps.clump(2).collect(_.every(_ > 0.01)).postln; + flags = amps.clump(2).collect(_.every(_ != 0)).postln; this.assert(flags[0], "Server: Pbind should play right after booting." ); From d184e3a12791bef5fa238194ce555f2091643f47 Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 10 Dec 2017 21:36:49 -0500 Subject: [PATCH 13/21] test suite: add comments to test_fourWaysToPlaySound also remove unused variable --- testsuite/classlibrary/TestServer_boot.sc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/testsuite/classlibrary/TestServer_boot.sc b/testsuite/classlibrary/TestServer_boot.sc index 62007e8961a..5e9db145f0b 100644 --- a/testsuite/classlibrary/TestServer_boot.sc +++ b/testsuite/classlibrary/TestServer_boot.sc @@ -98,10 +98,9 @@ TestServer_boot : UnitTest { } test_fourWaysToPlaySound { - var amps = []; - var flags; + var amps; // holds measured amplitudes of the 8 channels + var flags; // whether or not the amplitudes in each pair of channels was nonzero var o = OSCFunc({ |msg| amps = msg.drop(3) }, '/the8Amps'); - var cond = Condition(); var pbindPlayer; s.options.numOutputBusChannels = 8; @@ -113,6 +112,7 @@ TestServer_boot : UnitTest { { Saw.ar([220, 330], 0.1) }.play(s, 2); Synth(\default, [\out, 4], s); Ndef(\testX -> s.name, { PinkNoise.ar(0.1) ! 2 }).play(6); + // get 8 sound levels { SendReply.kr( @@ -124,11 +124,13 @@ TestServer_boot : UnitTest { s.sync; 2.wait; + // clean up pbindPlayer.stop; Ndef.dictFor(s).clear; s.quit; - flags = amps.clump(2).collect(_.every(_ != 0)).postln; + // check whether each pair of channels was nonzero + flags = amps.clump(2).collect(_.every(_ != 0)); this.assert(flags[0], "Server: Pbind should play right after booting." ); From 734b19b87be48085e916b20320686a5af1d44646 Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 10 Dec 2017 21:55:39 -0500 Subject: [PATCH 14/21] test suite: prefer assertEquals --- testsuite/classlibrary/TestServer_boot.sc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/classlibrary/TestServer_boot.sc b/testsuite/classlibrary/TestServer_boot.sc index 5e9db145f0b..30d18ea163e 100644 --- a/testsuite/classlibrary/TestServer_boot.sc +++ b/testsuite/classlibrary/TestServer_boot.sc @@ -25,7 +25,7 @@ TestServer_boot : UnitTest { s.sendMsg("/g_queryTree", 0); s.sync; - this.assert(queryReply == correctReply, + this.assertEquals(queryReply, correctReply, "Server boot should send volume synthdef and create synth immediately when set to nonzero volume."); s.quit; From f76fe9dce90824ec2ffe18dd1b3d8177c8700bd9 Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 10 Dec 2017 21:56:55 -0500 Subject: [PATCH 15/21] test suite: add postln so that PASS message is at start of line --- testsuite/classlibrary/TestServer_boot.sc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testsuite/classlibrary/TestServer_boot.sc b/testsuite/classlibrary/TestServer_boot.sc index 30d18ea163e..1767a4bbed1 100644 --- a/testsuite/classlibrary/TestServer_boot.sc +++ b/testsuite/classlibrary/TestServer_boot.sc @@ -91,6 +91,8 @@ TestServer_boot : UnitTest { prevNodeID = nodeID; }; + "Done."postln; + this.assert(failed.not, "allocating nodeIDs while booting should not produce duplicate nodeIDs." ); From 3947160aa279f09eec3e190e15ebc6c0f5918c8d Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 10 Dec 2017 22:16:03 -0500 Subject: [PATCH 16/21] test suite: remove wait from TestServer_boot::tearDown --- testsuite/classlibrary/TestServer_boot.sc | 1 - 1 file changed, 1 deletion(-) diff --git a/testsuite/classlibrary/TestServer_boot.sc b/testsuite/classlibrary/TestServer_boot.sc index 1767a4bbed1..65977037881 100644 --- a/testsuite/classlibrary/TestServer_boot.sc +++ b/testsuite/classlibrary/TestServer_boot.sc @@ -7,7 +7,6 @@ TestServer_boot : UnitTest { } tearDown { - 0.5.wait; s.remove; } From 7a5a9f89ef1dda572619ed88ddc9f55fbf25d722 Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 10 Dec 2017 22:26:18 -0500 Subject: [PATCH 17/21] test suite: move test from TestServer_boot into TestVolume Also rename to test_booting --- testsuite/classlibrary/TestServer_boot.sc | 20 -------------------- testsuite/classlibrary/TestVolume.sc | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/testsuite/classlibrary/TestServer_boot.sc b/testsuite/classlibrary/TestServer_boot.sc index 65977037881..19e876d0fde 100644 --- a/testsuite/classlibrary/TestServer_boot.sc +++ b/testsuite/classlibrary/TestServer_boot.sc @@ -10,26 +10,6 @@ TestServer_boot : UnitTest { s.remove; } - test_volume { - var queryReply; - var correctReply = [ '/g_queryTree.reply', 0, 0, 2, 1, 0, 1000, -1, 'volumeAmpControl2' ]; - - // set volume so its synthdef, synth and set get sent right after boot - s.volume.volume = -1; - s.bootSync; - - OSCFunc({ |msg| - queryReply = msg; - },'/g_queryTree.reply', s.addr).oneShot; - s.sendMsg("/g_queryTree", 0); - s.sync; - - this.assertEquals(queryReply, correctReply, - "Server boot should send volume synthdef and create synth immediately when set to nonzero volume."); - - s.quit; - } - test_waitForBoot { var vals = List[]; var of = OSCFunc({ |msg| vals.add(msg[3]) }, \tr, s.addr); diff --git a/testsuite/classlibrary/TestVolume.sc b/testsuite/classlibrary/TestVolume.sc index 71b0bd4606f..b6c152d1a5a 100644 --- a/testsuite/classlibrary/TestVolume.sc +++ b/testsuite/classlibrary/TestVolume.sc @@ -1,5 +1,26 @@ TestVolume : UnitTest { + test_booting { + var s = Server.default; + var correctReply = [ '/g_queryTree.reply', 0, 0, 2, 1, 0, 1000, -1, 'volumeAmpControl2' ]; + var queryReply; + + // set volume so its synthdef, synth and set get sent right after boot + s.volume.volume = -1; + s.bootSync; + + OSCFunc({ |msg| + queryReply = msg; + },'/g_queryTree.reply', s.addr).oneShot; + s.sendMsg("/g_queryTree", 0); + s.sync; + + this.assertEquals(queryReply, correctReply, + "Server boot should send volume synthdef and create synth immediately when set to nonzero volume."); + + s.quit; + } + test_setVolume { var s, ampSynthVolume; From 0273c8e2df8f73ebf4eb7a0448968fe5f399ce69 Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 10 Dec 2017 22:26:35 -0500 Subject: [PATCH 18/21] test suite: add fix for sporadically failing test in TestVolume --- testsuite/classlibrary/TestVolume.sc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/testsuite/classlibrary/TestVolume.sc b/testsuite/classlibrary/TestVolume.sc index b6c152d1a5a..19525d9329c 100644 --- a/testsuite/classlibrary/TestVolume.sc +++ b/testsuite/classlibrary/TestVolume.sc @@ -9,6 +9,10 @@ TestVolume : UnitTest { s.volume.volume = -1; s.bootSync; + // FIXME: wait for Volume synth to be requested after boot. Since there is no programmatic way + // to check when this request has been sent, we have to do this the uncomfortable way. + 0.2.wait; + OSCFunc({ |msg| queryReply = msg; },'/g_queryTree.reply', s.addr).oneShot; From 2ebef7f2674ca7e389d78fedda4e9f31f5e4a5c6 Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 10 Dec 2017 22:32:02 -0500 Subject: [PATCH 19/21] test suite: fix typo in testServer_boot --- testsuite/classlibrary/TestServer_boot.sc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/classlibrary/TestServer_boot.sc b/testsuite/classlibrary/TestServer_boot.sc index 19e876d0fde..03f6505b4dd 100644 --- a/testsuite/classlibrary/TestServer_boot.sc +++ b/testsuite/classlibrary/TestServer_boot.sc @@ -70,7 +70,7 @@ TestServer_boot : UnitTest { prevNodeID = nodeID; }; - "Done."postln; + "Done.".postln; this.assert(failed.not, "allocating nodeIDs while booting should not produce duplicate nodeIDs." From f4e3bd02a50a4c8c506080c40a24eacfa8978be1 Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Mon, 11 Dec 2017 18:08:04 -0500 Subject: [PATCH 20/21] test suite: correct test_allocWhileBooting Should only wait for s.serverRunniing to start allocating (@adcxyz) --- testsuite/classlibrary/TestServer_boot.sc | 24 +++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/testsuite/classlibrary/TestServer_boot.sc b/testsuite/classlibrary/TestServer_boot.sc index 03f6505b4dd..66c2478f188 100644 --- a/testsuite/classlibrary/TestServer_boot.sc +++ b/testsuite/classlibrary/TestServer_boot.sc @@ -52,14 +52,34 @@ TestServer_boot : UnitTest { s.quit; } + // Check that we can never create duplicate nodeIDs once server.serverRunning + // is true, even if the server has not been fully synced yet. test_allocWhileBooting { var prevNodeID = -1; var nodeID = 0; var failed = false; - this.bootServer(s); + s.boot; + + // wait until serverRunning is true, for up to 5 seconds + block { |break| + 5000.do { + if(s.serverRunning) { + break.value + } { + 0.001.wait; + } + } + }; + + // exit early if server boot fails + if(s.serverRunning.not) { + this.assert(false, "Server did not boot after 5 seconds."); + s.quit; + ^nil + }; - 1000.do { + 100.do { ".".post; nodeID = s.nextNodeID; if(nodeID <= prevNodeID) { From c557697064ffd94adb527f8c8a165627d13bbee6 Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Mon, 11 Dec 2017 18:09:40 -0500 Subject: [PATCH 21/21] test suite: correct test_fourWaysToPlaySound Code should use waitForBoot rename test to reflect this --- testsuite/classlibrary/TestServer_boot.sc | 55 ++++++++++++++--------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/testsuite/classlibrary/TestServer_boot.sc b/testsuite/classlibrary/TestServer_boot.sc index 66c2478f188..128bf3aa301 100644 --- a/testsuite/classlibrary/TestServer_boot.sc +++ b/testsuite/classlibrary/TestServer_boot.sc @@ -98,37 +98,52 @@ TestServer_boot : UnitTest { s.quit; } - test_fourWaysToPlaySound { + // Check that with s.waitForBoot, the four most common ways of creating sound processes will work. + test_waitForBoot_fourWaysToPlaySound { var amps; // holds measured amplitudes of the 8 channels var flags; // whether or not the amplitudes in each pair of channels was nonzero var o = OSCFunc({ |msg| amps = msg.drop(3) }, '/the8Amps'); var pbindPlayer; + var cond = Condition(); // signalled at end of collecting results s.options.numOutputBusChannels = 8; - this.bootServer(s); - - // 4 ways to make sounds on the first 8 chans - pbindPlayer = Pbind(\legato, 1.1, \server, s).play; - { Saw.ar([220, 330], 0.1) }.play(s, 2); - Synth(\default, [\out, 4], s); - Ndef(\testX -> s.name, { PinkNoise.ar(0.1) ! 2 }).play(6); + s.waitForBoot { + // 4 ways to make sounds on the first 8 chans + pbindPlayer = Pbind(\legato, 1.1, \server, s).play; + { Saw.ar([220, 330], 0.1) }.play(s, 2); + Synth(\default, [\out, 4], s); + Ndef(\testX -> s.name, { PinkNoise.ar(0.1) ! 2 }).play(6); + + // get 8 sound levels + { + SendReply.kr( + Impulse.kr(10), '/the8Amps', + Amplitude.kr(InFeedback.ar(0, 8), 0.001, 1), + ) + }.play(s); + + s.sync; + 1.wait; - // get 8 sound levels - { - SendReply.kr( - Impulse.kr(10), '/the8Amps', - Amplitude.kr(InFeedback.ar(0, 8), 0.001, 1), - ) - }.play(s); + // clean up + pbindPlayer.stop; + Ndef.dictFor(s).clear; + cond.test_(true).unhang; + }; - s.sync; - 2.wait; + // wait for 5 seconds or for unhang + cond.hang(5); // clean up - pbindPlayer.stop; - Ndef.dictFor(s).clear; s.quit; + o.free; + + // exit early if server booting failed + if(cond.test.not) { + this.assert(false, "Server failed to boot after 5 seconds."); + ^nil + }; // check whether each pair of channels was nonzero flags = amps.clump(2).collect(_.every(_ != 0)); @@ -144,7 +159,5 @@ TestServer_boot : UnitTest { this.assert(flags[3], "Server: Ndef should play right after booting." ); - - o.free; } }