public void should_reuse_last_endpoint_port_when_available_in_current_dir() { const string peerId = "Abc.Peer.0"; var expectedPortFilePath = PathUtil.InBaseDirectory(peerId + ".inboundport.test"); var expectedPort = TcpUtil.GetRandomUnusedPort(); File.WriteAllText(expectedPortFilePath, expectedPort.ToString()); var transport = CreateAndStartZmqTransport(peerId: peerId); var endpoint = new ZmqEndPoint(transport.InboundEndPoint); endpoint.GetPort().ShouldEqual(expectedPort); }
public void should_not_reuse_a_port_used_in_another_envionment() { const string peerId = "Abc.Peer.0"; var doNotUsePortFilePath = PathUtil.InBaseDirectory(peerId + ".inboundport.secondenv"); var expectedPort = TcpUtil.GetRandomUnusedPort() + 5; // scientifical method to determine what port will be used by the transport :P File.WriteAllText(doNotUsePortFilePath, expectedPort.ToString()); var transport = CreateAndStartZmqTransport(peerId: peerId); var endpoint = new ZmqEndPoint(transport.InboundEndPoint); endpoint.GetPort().ShouldNotEqual(expectedPort); Console.WriteLine("{0} => {1}", endpoint.GetPort(), expectedPort); }
public void should_save_last_endpoint() { const string peerId = "Abc.Peer.0"; var expectedPortFilePath = PathUtil.InBaseDirectory(Path.Combine("Data", peerId + ".inboundport.test")); if (File.Exists(expectedPortFilePath)) { File.Delete(expectedPortFilePath); } var transport = CreateAndStartZmqTransport(peerId: peerId); var port = new ZmqEndPoint(transport.InboundEndPoint).GetPort(); expectedPortFilePath.ShouldExists(); var portFromFile = int.Parse(File.ReadAllText(expectedPortFilePath)); portFromFile.ShouldEqual(port); }