/// <summary> /// This executes the test case on the server. /// </summary> public MFTestResults RunTest(string testToRun, int scenarioToRun) { TestProxy tp = new TestProxy(); //When calling this method pass in the TestProxy default values. return(RunTest(testToRun, tp.serverTimeoutSeconds, tp.serverTestResult, scenarioToRun)); }
public static void ValidateTestProxy() { TestProxy tp = new TestProxy(); tp.serverTestResult = MFTestResults.Pass; tp.serverTimeoutSeconds = int.MinValue; tp.testToRun = "T"; TestProxy tpCopy = tp; byte [] serializedData = tp.Serialize(); tp.Deserialize(serializedData); if ((tpCopy.serverTestResult == tp.serverTestResult)&&(tpCopy.serverTimeoutSeconds == tp.serverTimeoutSeconds)&&(tpCopy.testToRun == tp.testToRun)) Debug.Print("Pass"); else Debug.Print("Fail"); }
/// <summary> /// This executes the test case on the server. /// </summary> /// <param name="testToRun">The name of the test to execute.</param> /// <param name="serverTimeoutSeconds">The amount of time that the server should run the test case. If it times out then something is wrong.</param> /// <param name="serverTestResult">The return value that the server sends back to the client.</param> public MFTestResults RunTest(string testToRun, int serverTimeoutSeconds, MFTestResults serverTestResult, int scenarioToRun) { MFTestResults testResult = MFTestResults.Fail; currentTestCase = new TestProxy(); currentTestCase.testToRun = testToRun; currentTestCase.serverTimeoutSeconds = serverTimeoutSeconds; currentTestCase.serverTestResult = serverTestResult; currentTestCase.scenarioToRun = scenarioToRun; try { if (socket != null) { try { Thread.Sleep(350); //send the test that the client wants to execute to the server. socket.Send(currentTestCase.Serialize()); testResult = MFTestResults.Pass; } catch (Exception e) { Debug.Print("Exception trying to send test to run with exception: " + e.ToString()); } } } catch (SocketException e) { Log.Comment("Exception trying to send/receive from server."); Log.Comment("Error Code:" + e.ErrorCode); } catch (Exception e) { Log.Comment("Exception:" + e.ToString()); } return(testResult); }
/// <summary> /// This executes the test case on the server. /// </summary> /// <param name="testToRun">The name of the test to execute.</param> /// <param name="serverTimeoutSeconds">The amount of time that the server should run the test case. If it times out then something is wrong.</param> /// <param name="serverTestResult">The return value that the server sends back to the client.</param> public MFTestResults RunTest(string testToRun, int serverTimeoutSeconds, MFTestResults serverTestResult, int scenarioToRun) { MFTestResults testResult = MFTestResults.Fail; currentTestCase = new TestProxy(); currentTestCase.testToRun = testToRun; currentTestCase.serverTimeoutSeconds = serverTimeoutSeconds; currentTestCase.serverTestResult = serverTestResult; currentTestCase.scenarioToRun = scenarioToRun; try { if (socket != null) { try { Thread.Sleep(350); //send the test that the client wants to execute to the server. socket.Send(currentTestCase.Serialize()); testResult = MFTestResults.Pass; } catch (Exception e) { Debug.Print("Exception trying to send test to run with exception: " + e.ToString()); } } } catch (SocketException e) { Log.Comment("Exception trying to send/receive from server."); Log.Comment("Error Code:" + e.ErrorCode); } catch (Exception e) { Log.Comment("Exception:" + e.ToString()); } return testResult; }
public static void ValidateTestProxy() { TestProxy tp = new TestProxy(); tp.serverTestResult = MFTestResults.Pass; tp.serverTimeoutSeconds = int.MinValue; tp.testToRun = "T"; TestProxy tpCopy = tp; byte [] serializedData = tp.Serialize(); tp.Deserialize(serializedData); if ((tpCopy.serverTestResult == tp.serverTestResult) && (tpCopy.serverTimeoutSeconds == tp.serverTimeoutSeconds) && (tpCopy.testToRun == tp.testToRun)) { Debug.Print("Pass"); } else { Debug.Print("Fail"); } }
public MFTestResults GetTestResult() { MFTestResults testResult = MFTestResults.Fail; if (socket != null) { byte[] receiveBuffer = new byte[1000]; int len = 0; if (socket.Poll(-1, SelectMode.SelectRead)) { Thread.Sleep(50); len = socket.Available; if (len > receiveBuffer.Length) { len = receiveBuffer.Length; } len = socket.Receive(receiveBuffer, len, SocketFlags.None); if (len > 0) { TestProxy tp = new TestProxy(receiveBuffer); testResult = tp.serverTestResult; } } } else { Log.Comment("Must Initialize and Start the TestManager before calling GetTestResult()."); } return(testResult); }
public MFTestResults GetTestResult() { MFTestResults testResult = MFTestResults.Fail; if (socket != null) { byte[] receiveBuffer = new byte[1000]; int len = 0; if (socket.Poll(-1, SelectMode.SelectRead)) { Thread.Sleep(50); len = socket.Available; if (len > receiveBuffer.Length) len = receiveBuffer.Length; len = socket.Receive(receiveBuffer, len, SocketFlags.None); if (len > 0) { TestProxy tp = new TestProxy(receiveBuffer); testResult = tp.serverTestResult; } } } else Log.Comment("Must Initialize and Start the TestManager before calling GetTestResult()."); return testResult; }
/// <summary> /// This executes the test case on the server. /// </summary> public MFTestResults RunTest(string testToRun, int scenarioToRun) { TestProxy tp = new TestProxy(); //When calling this method pass in the TestProxy default values. return RunTest(testToRun, tp.serverTimeoutSeconds, tp.serverTestResult, scenarioToRun); }
public void Start(object classOfTests) { //Continually run and try to make a connection to the device. while (true) { try { //If we can't connect then an exception will be thrown. Thus retrying to connect. socket.Connect(ipAddress, port); Console.WriteLine("Connected."); int quitCounter = 0; //Now we have a connection so continually receive a test to run, execute it, then report the result back. while (true) { byte[] receiveBuffer = new byte[1000]; int dataAvailable = 0; //Waiting for device to request a test to execute. //If loose connection OR no more tests to execute this will throw an exception on Read Timeout. //Thus putting us back into the Connect loop. dataAvailable = socket.Receive(receiveBuffer, SocketFlags.None); //Continue if we've read something. if (dataAvailable > 0) { quitCounter = 0; TestProxy tp = new TestProxy(receiveBuffer); classOfTestsToRun = classOfTests; testToRun = tp.testToRun; scenarioToRun = tp.scenarioToRun; //do this in process RunTest(); tp.serverTestResult = testResult; socket.Send(tp.Serialize(), SocketFlags.None); } else { quitCounter++; //only try to recieve 20 times then go back to try and connect. if (quitCounter > 20) { break; } } } } catch (SocketException e) { //Error code 10061 is connection refused because server is not running yet. //ignore this error code. if (e.ErrorCode != 10061) { Console.WriteLine("SocketException: " + e); Console.WriteLine("Error Code: " + e.ErrorCode); } } catch (Exception e) { Console.WriteLine("Exception: " + e.ToString()); } finally { if (socket != null) { socket.Close(); socket = null; } //reinitilize and start the loop over again to reconnect to the device. Initialize(ipAddress, port); } Thread.Sleep(2000); } }
public void Start(object classOfTests) { //Continually run and try to make a connection to the device. while (true) { try { //If we can't connect then an exception will be thrown. Thus retrying to connect. socket.Connect(ipAddress, port); Console.WriteLine("Connected."); int quitCounter = 0; //Now we have a connection so continually receive a test to run, execute it, then report the result back. while (true) { byte[] receiveBuffer = new byte[1000]; int dataAvailable = 0; //Waiting for device to request a test to execute. //If loose connection OR no more tests to execute this will throw an exception on Read Timeout. //Thus putting us back into the Connect loop. dataAvailable = socket.Receive(receiveBuffer, SocketFlags.None); //Continue if we've read something. if (dataAvailable > 0) { quitCounter = 0; TestProxy tp = new TestProxy(receiveBuffer); classOfTestsToRun = classOfTests; testToRun = tp.testToRun; scenarioToRun = tp.scenarioToRun; //do this in process RunTest(); tp.serverTestResult = testResult; socket.Send(tp.Serialize(), SocketFlags.None); } else { quitCounter++; //only try to recieve 20 times then go back to try and connect. if (quitCounter > 20) break; } } } catch (SocketException e) { //Error code 10061 is connection refused because server is not running yet. //ignore this error code. if (e.ErrorCode != 10061) { Console.WriteLine("SocketException: " + e); Console.WriteLine("Error Code: " + e.ErrorCode); } } catch (Exception e) { Console.WriteLine("Exception: " + e.ToString()); } finally { if (socket != null) { socket.Close(); socket = null; } //reinitilize and start the loop over again to reconnect to the device. Initialize(ipAddress, port); } Thread.Sleep(2000); } }