public async Task Start_ShouldLaunch_NetInitEvent() { NetworkInitializedEvent eventData = null; _eventBus.Subscribe <NetworkInitializedEvent>(ed => { eventData = ed; return(Task.CompletedTask); }); await _networkServer.StartAsync(); await _networkServer.StopAsync(); eventData.ShouldNotBeNull(); }
public async Task NetworkServer_Stop_Test() { await _networkServer.StopAsync(false); var peers = _peerPool.GetPeers(true).Cast <GrpcPeer>(); foreach (var peer in peers) { peer.IsReady.ShouldBeFalse(); } }
public async Task StopAsync(OsBlockchainNodeContext blockchainNodeContext) { await _networkServer.StopAsync(false); await _blockchainNodeContextService.StopAsync(blockchainNodeContext.BlockchainNodeContext); foreach (var nodePlugin in _nodePlugins) { var _ = nodePlugin.ShutdownAsync(); } }
public async Task Calling_DisposedPeer_ThrowsUnrecoverableNEtException() { await _networkServer.StartAsync(); Channel channel = new Channel("localhost", 2001, ChannelCredentials.Insecure); PeerService.PeerServiceClient peerClient = new PeerService.PeerServiceClient(channel); GrpcClient grpcClient = new GrpcClient(channel, peerClient); AElfPeerEndpointHelper.TryParse("127.0.0.1:2001", out var endpoint); GrpcPeer peer = new GrpcPeer(grpcClient, endpoint, new PeerConnectionInfo { SessionId = new byte[] { 1, 2, 3 } }); await peer.DisconnectAsync(false); var exHealthCheck = await Assert.ThrowsAsync <NetworkException>(async() => await peer.CheckHealthAsync()); exHealthCheck.ExceptionType.ShouldBe(NetworkExceptionType.Unrecoverable); var exGetBlocks = await Assert.ThrowsAsync <NetworkException>( async() => await peer.GetBlocksAsync(Hash.FromString("blockHash"), 10)); exGetBlocks.ExceptionType.ShouldBe(NetworkExceptionType.Unrecoverable); var exGetBlock = await Assert.ThrowsAsync <NetworkException>( async() => await peer.GetBlockByHashAsync(Hash.FromString("blockHash"))); exGetBlock.ExceptionType.ShouldBe(NetworkExceptionType.Unrecoverable); var exGetNodes = await Assert.ThrowsAsync <NetworkException>( async() => await peer.GetNodesAsync()); exGetNodes.ExceptionType.ShouldBe(NetworkExceptionType.Unrecoverable); await _networkServer.StopAsync(); }
public async Task StartServer_Test() { NetworkInitializedEvent received = null; _eventBus.Subscribe <NetworkInitializedEvent>(a => { received = a; return(Task.CompletedTask); }); await _networkServer.StartAsync(); received.ShouldNotBeNull(); await _networkServer.StopAsync(); }
public async Task StartServer_Test() { NetworkInitializedEvent received = null; _eventBus.Subscribe <NetworkInitializedEvent>(a => { received = a; return(Task.CompletedTask); }); await _networkServer.StartAsync(); received.ShouldNotBeNull(); var reconnections = _reconnectionService.GetPeersReadyForReconnection(null); reconnections.Count.ShouldBe(1); reconnections.First().Endpoint.ShouldBe("127.0.0.1:2018"); await _networkServer.StopAsync(); }
public override void Dispose() { AsyncHelper.RunSync(() => _networkServer.StopAsync(false)); }