public async Task SocketClosing() { var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod()); log.Info("Start"); var closed = false; var error = false; var options = CreateOptions(); socket = new Socket("ws://0.0.0.0:8080", options); socket.On(Socket.EVENT_OPEN, () => { log.Info("EVENT_OPEN"); //socket.Send("test send"); }); socket.On(Socket.EVENT_CLOSE, () => { log.Info("EVENT_CLOSE = "); closed = true; }); socket.Once(Socket.EVENT_ERROR, () => { log.Info("EVENT_ERROR = "); error = true; }); socket.Open(); //System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1)); await Task.Delay(1000); Assert.True(closed); Assert.True(error); }
public void SocketClosing() { LogManager.SetupLogManager(); var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod()); log.Info("Start"); var ManualResetEvent = new ManualResetEvent(false); var closed = false; //var error = false; var options = CreateOptions(); socket = new Socket("ws://0.0.0.0:8080", options); socket.On(Socket.EVENT_OPEN, () => { log.Info("EVENT_OPEN"); //socket.Send("test send"); }); socket.On(Socket.EVENT_CLOSE, () => { log.Info("EVENT_CLOSE = "); closed = true; ManualResetEvent.Set(); }); socket.Once(Socket.EVENT_ERROR, () => { log.Info("EVENT_ERROR = "); //error = true; }); socket.Open(); ManualResetEvent.WaitOne(); log.Info("After WaitOne"); Assert.IsTrue(closed); //Assert.IsTrue(error); }
public void SocketClosing() { var log = LogManager.GetLogger(Global.CallerName()); log.Info("Start"); _manualResetEvent = new ManualResetEvent(false); var manualResetEventError = new ManualResetEvent(false); var closed = false; var error = false; var options = CreateOptions(); socket = new Socket("ws://0.0.0.0:8080", options); socket.On(Socket.EVENT_OPEN, () => { log.Info("EVENT_OPEN"); //socket.Send("test send"); }); socket.On(Socket.EVENT_CLOSE, () => { log.Info("EVENT_CLOSE = "); closed = true; _manualResetEvent.Set(); }); socket.Once(Socket.EVENT_ERROR, () => { log.Info("EVENT_ERROR = "); error = true; manualResetEventError.Set(); }); socket.Open(); _manualResetEvent.WaitOne(); manualResetEventError.WaitOne(); Assert.IsTrue(closed); Assert.IsTrue(error); }