Skip to content

Commit 8f1b07b

Browse files
committed
dotnet core tests runner
- reimplement connection timeouts - make it build against mono/.NET again
1 parent c1fd46c commit 8f1b07b

31 files changed

+14286
-4933
lines changed

projects/client/RabbitMQ.Client/RabbitMQ.Client.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@
182182
<Compile Include="src\client\impl\StreamProperties.cs" />
183183
<Compile Include="src\client\impl\SyntaxError.cs" />
184184
<Compile Include="src\client\impl\TcpClientAdapter.cs" />
185-
<Compile Include="src\client\impl\TunneledTcpClient.cs" />
186185
<Compile Include="src\client\impl\UnexpectedFrameException.cs" />
187186
<Compile Include="src\client\impl\UnknownClassOrMethodException.cs" />
188187
<Compile Include="src\client\impl\WireFormatting.cs" />
@@ -207,4 +206,4 @@
207206
<Target Name="BeforeBuild" DependsOnTargets="" />
208207
<!-- Custom BeforeClean -->
209208
<Target Name="BeforeClean" DependsOnTargets="" />
210-
</Project>
209+
</Project>

projects/client/RabbitMQ.Client/project.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
{
22
"version": "1.0.0-*",
33
"buildOptions": {
4-
"emitEntryPoint": true
4+
"emitEntryPoint": true,
5+
"compile": {
6+
"exclude": [
7+
"build",
8+
"src/util/XmlUtil.cs"
9+
],
10+
"include": [
11+
"../../../gensrc/RabbitMQ.Client/autogenerated-api-0-9-1.cs"
12+
]
13+
}
514
},
615
"dependencies": {
716
"Microsoft.NETCore.App": {
817
"type": "platform",
918
"version": "1.0.0-rc2-3002702"
1019
}
1120
},
12-
"code": ["**/*.cs"],
1321
"frameworks": {
1422
"netcoreapp1.0": {
23+
"buildOptions": {
24+
"define": [ "CORECLR" ]
25+
},
1526
"imports": "dnxcore50",
1627
"dependencies": {
1728
"System.Runtime": "4.1.0-rc2-24027",

projects/client/RabbitMQ.Client/src/autogenerated-api-0-9-1.cs

Lines changed: 0 additions & 4389 deletions
This file was deleted.

projects/client/RabbitMQ.Client/src/client/api/ConnectionFactoryBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static ITcpClient DefaultSocketFactory(AddressFamily addressFamily)
7979
NoDelay = true
8080
};
8181
return new TcpClientAdapter(socket);
82-
}
82+
}
8383
#endif
8484
}
8585
}

projects/client/RabbitMQ.Client/src/client/api/ITcpClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface ITcpClient
1717

1818
Socket Client { get; }
1919

20-
void Connect(string host, int port);
20+
Task ConnectAsync(string host, int port);
2121

2222
NetworkStream GetStream();
2323

projects/client/RabbitMQ.Client/src/client/impl/ConsumerWorkService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public void ExecuteThunk()
5757
#if NETFX_CORE
5858
// To end a task, return
5959
return;
60-
#else
61-
//Thread.CurrentThread..Interrupt(); //TODO: what to do?
60+
#else
61+
//Thread.CurrentThread.Interrupt(); //TODO: what to do?
6262
#endif
6363
}
6464
}

projects/client/RabbitMQ.Client/src/client/impl/SocketFrameHandler.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,21 @@
4646
using System.Collections.Generic;
4747
using System.Net.Sockets;
4848
using System.Text;
49+
using System.Threading.Tasks;
4950

5051
namespace RabbitMQ.Client.Impl
5152
{
53+
static class TaskExtensions
54+
{
55+
public static async Task TimeoutAfter(this Task task, int millisecondsTimeout)
56+
{
57+
if (task == await Task.WhenAny(task, Task.Delay(millisecondsTimeout)))
58+
await task;
59+
else
60+
throw new TimeoutException();
61+
}
62+
}
63+
5264
public class SocketFrameHandler : IFrameHandler
5365
{
5466
// Timeout in seconds to wait for a clean socket close.
@@ -262,7 +274,11 @@ private void Connect(ITcpClient socket, AmqpTcpEndpoint endpoint, int timeout)
262274
{
263275
try
264276
{
265-
socket.Connect(endpoint.HostName, endpoint.Port);
277+
socket.ConnectAsync(endpoint.HostName, endpoint.Port)
278+
.TimeoutAfter(timeout)
279+
.ConfigureAwait(false)
280+
.GetAwaiter()//this ensures exceptions aren't wrapped in an AggregateException
281+
.GetResult();
266282
}
267283
catch (ArgumentException e)
268284
{
@@ -271,6 +287,11 @@ private void Connect(ITcpClient socket, AmqpTcpEndpoint endpoint, int timeout)
271287
catch (SocketException e)
272288
{
273289
throw new ConnectFailureException("Connection failed", e);
290+
}
291+
catch (TimeoutException)
292+
{
293+
socket.Close();
294+
throw new TimeoutException("Connection to " + endpoint + " timed out");;
274295
}
275296
}
276297
}

projects/client/RabbitMQ.Client/src/client/impl/TcpClientAdapter.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ public TcpClientAdapter(Socket socket)
2424
this.sock = socket;
2525
}
2626

27-
public virtual void Connect(string host, int port)
27+
public virtual Task ConnectAsync(string host, int port)
2828
{
29-
var _host = IPAddress.Parse("127.0.0.1");
30-
var ep =new IPEndPoint(_host, port);
31-
32-
sock.Connect(ep);
29+
#if CORECLR
30+
return sock.ConnectAsync(host, port);
31+
#else
32+
sock.Connect(host, port);
33+
return System.Threading.Tasks.Task.FromResult (false);
34+
#endif
3335
}
3436

3537
public virtual void Close()

0 commit comments

Comments
 (0)