This commit is contained in:
xinchen 2016-10-29 20:45:19 -07:00
Родитель 35bc4eb90c
Коммит e847ab0f76
5 изменённых файлов: 46 добавлений и 19 удалений

Просмотреть файл

@ -101,6 +101,8 @@ IF /I "%build-target%" == "build" GOTO :build-target
IF /I "%build-target%" == "test" GOTO :build-done
GOTO :args-error
TASKKILL /F /IM TestAmqpBroker.exe >nul 2>&1
:build-clean
CALL :run-build Clean
SET return-code=%ERRORLEVEL%

Просмотреть файл

@ -11,7 +11,9 @@
"../../test/Common/Assert.cs",
"../../test/Common/NamedPipeTransport.cs",
"../../test/Common/TestTarget.cs",
"../../test/Common/TestListener.cs",
"../../test/Common/LinkTests.cs",
"../../test/Common/ProtocolTests.cs",
"../../test/Common/UtilityTests.cs",
"../../test/Common/ContainerHostTests.cs",
"../../test/Common/Types/*.cs",

Просмотреть файл

@ -35,12 +35,12 @@ namespace Test.Amqp
static ProtocolTests()
{
Trace.TraceLevel = TraceLevel.Frame;
Trace.TraceListener = (f, a) => System.Diagnostics.Trace.WriteLine(System.DateTime.Now.ToString("[hh:mm:ss.fff]") + " " + string.Format(f, a));
//Trace.TraceLevel = TraceLevel.Frame;
//Trace.TraceListener = (f, a) => System.Diagnostics.Trace.WriteLine(System.DateTime.Now.ToString("[hh:mm:ss.fff]") + " " + string.Format(f, a));
}
[TestInitialize]
public void Initialize()
public void TestInitialize()
{
this.testListener = new TestListener(new IPEndPoint(IPAddress.Any, port));
this.testListener.Open();
@ -48,7 +48,7 @@ namespace Test.Amqp
}
[TestCleanup]
public void Cleanup()
public void TestCleanup()
{
this.testListener.Close();
}

Просмотреть файл

@ -56,6 +56,7 @@ namespace Test.Amqp
readonly IPEndPoint ip;
readonly Dictionary<TestPoint, TestFunc> testPoints;
Socket socket;
SocketAsyncEventArgs args;
public TestListener(IPEndPoint ip)
{
@ -79,10 +80,13 @@ namespace Test.Amqp
public void Open()
{
this.args = new SocketAsyncEventArgs();
this.args.Completed += this.OnAccept;
this.socket = new Socket(this.ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp) { NoDelay = true };
this.socket.Bind(this.ip);
this.socket.Listen(20);
this.socket.BeginAccept(OnAccept, this);
this.Accept();
}
public void Close()
@ -90,6 +94,7 @@ namespace Test.Amqp
Socket s = this.socket;
this.socket = null;
if (s != null) s.Dispose();
if (this.args != null) this.args.Dispose();
}
public void RegisterTarget(TestPoint point, TestFunc func)
@ -117,27 +122,43 @@ namespace Test.Amqp
}
}
static void OnAccept(IAsyncResult result)
void Accept()
{
TestListener thisPtr = (TestListener)result.AsyncState;
if (thisPtr.socket == null) return;
Socket s = this.socket;
while (s != null)
{
try
{
if (this.socket.AcceptAsync(this.args))
{
break;
}
try
{
Socket socket = thisPtr.socket.EndAccept(result);
socket.NoDelay = true;
Fx.StartThread(() => thisPtr.Pump(new NetworkStream(socket, true)));
this.args.UserToken = "sync";
this.OnAccept(s, this.args);
}
catch { }
s = this.socket;
}
catch (Exception exception)
}
void OnAccept(object sender, SocketAsyncEventArgs args)
{
if (args.SocketError == SocketError.Success)
{
Trace.WriteLine(TraceLevel.Error, exception.ToString());
Socket s = args.AcceptSocket;
s.NoDelay = true;
Fx.StartThread(() => this.Pump(new NetworkStream(s, true)));
}
try
bool sync = args.UserToken != null;
args.UserToken = null;
args.AcceptSocket = null;
if (!sync)
{
thisPtr.socket.BeginAccept(OnAccept, thisPtr);
this.Accept();
}
catch { }
}
TestOutcome HandleTestPoint(TestPoint point, Stream stream, ushort channel, List fields)

Просмотреть файл

@ -64,6 +64,9 @@
<Compile Include="..\Common\LinkTests.cs">
<Link>LinkTests.cs</Link>
</Compile>
<Compile Include="..\Common\ProtocolTests.cs">
<Link>ProtocolTests.cs</Link>
</Compile>
<Compile Include="..\Common\TestListener.cs">
<Link>Common\TestListener.cs</Link>
</Compile>
@ -107,7 +110,6 @@
<Link>WebSocketTests.cs</Link>
</Compile>
<Compile Include="AmqpCodecTests.cs" />
<Compile Include="ProtocolTests.cs" />
<Compile Include="TransactionTests.cs" />
<Compile Include="PerfTests.cs" />
<Compile Include="TaskTests.cs" />