WhenAllOrAnyFailedWithTimeout() public static method

public static WhenAllOrAnyFailedWithTimeout ( ) : Task
return Task
Esempio n. 1
0
        public async Task Connect_Success(IPAddress listenAt)
        {
            int port;

            using (SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, listenAt, out port))
            {
                using (Socket client = new Socket(listenAt.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
                {
                    Task connectTask = ConnectAsync(client, new IPEndPoint(listenAt, port));
                    await TestSettings.WhenAllOrAnyFailedWithTimeout(connectTask);

                    Assert.True(client.Connected);
                }
            }
        }
Esempio n. 2
0
        public async Task Connect_MultipleIPAddresses_Success(IPAddress listenAt)
        {
            if (!SupportsMultiConnect)
            {
                return;
            }

            int port;

            using (SocketTestServer.SocketTestServerFactory(SocketImplementationType.Async, listenAt, out port))
                using (Socket client = new Socket(listenAt.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
                {
                    Task connectTask = MultiConnectAsync(client, new IPAddress[] { IPAddress.Loopback, IPAddress.IPv6Loopback }, port);
                    await TestSettings.WhenAllOrAnyFailedWithTimeout(connectTask);

                    Assert.True(client.Connected);
                }
        }
Esempio n. 3
0
        public async Task ConcurrentSendReceive(bool forceNonBlocking)
        {
            using (Socket server = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified))
                using (Socket client = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified))
                {
                    const int Iters       = 25;
                    byte[]    sendData    = new byte[Iters];
                    byte[]    receiveData = new byte[sendData.Length];
                    Random.Shared.NextBytes(sendData);

                    string path = GetRandomNonExistingFilePath();

                    server.Bind(new UnixDomainSocketEndPoint(path));
                    server.Listen(1);

                    Task <Socket> acceptTask = server.AcceptAsync();
                    client.Connect(new UnixDomainSocketEndPoint(path));
                    await  acceptTask;
                    Socket accepted = acceptTask.Result;

                    client.ForceNonBlocking(forceNonBlocking);
                    accepted.ForceNonBlocking(forceNonBlocking);

                    Task[]       writes = new Task[Iters];
                    Task <int>[] reads  = new Task <int> [Iters];
                    for (int i = 0; i < Iters; i++)
                    {
                        reads[i] = Task.Factory.StartNew(s => accepted.Receive(receiveData, (int)s, 1, SocketFlags.None), i,
                                                         CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
                    }
                    for (int i = 0; i < Iters; i++)
                    {
                        writes[i] = Task.Factory.StartNew(s => client.Send(sendData, (int)s, 1, SocketFlags.None), i,
                                                          CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
                    }
                    await TestSettings.WhenAllOrAnyFailedWithTimeout(writes.Concat(reads).ToArray());

                    AssertExtensions.SequenceEqual(sendData.OrderBy(i => i).ToArray(), receiveData.OrderBy(i => i).ToArray());
                }
        }
Esempio n. 4
0
        public async Task ConcurrentSendReceiveAsync()
        {
            using (Socket server = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified))
                using (Socket client = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified))
                {
                    const int Iters       = 2048;
                    byte[]    sendData    = new byte[Iters];
                    byte[]    receiveData = new byte[sendData.Length];
                    Random.Shared.NextBytes(sendData);

                    string path = GetRandomNonExistingFilePath();

                    server.Bind(new UnixDomainSocketEndPoint(path));
                    server.Listen(1);

                    Task <Socket> acceptTask = server.AcceptAsync();
                    client.Connect(new UnixDomainSocketEndPoint(path));
                    await  acceptTask;
                    Socket accepted = acceptTask.Result;

                    Task[]       writes = new Task[Iters];
                    Task <int>[] reads  = new Task <int> [Iters];
                    for (int i = 0; i < Iters; i++)
                    {
                        writes[i] = client.SendAsync(new ArraySegment <byte>(sendData, i, 1), SocketFlags.None);
                    }
                    for (int i = 0; i < Iters; i++)
                    {
                        reads[i] = accepted.ReceiveAsync(new ArraySegment <byte>(receiveData, i, 1), SocketFlags.None);
                    }

                    await TestSettings.WhenAllOrAnyFailedWithTimeout(writes.Concat(reads).ToArray());

                    AssertExtensions.SequenceEqual(sendData, receiveData);
                }
        }