Skip to content

Commit

Permalink
Fix Test Failures in SendResumption Tests (#1970)
Browse files Browse the repository at this point in the history
  • Loading branch information
nibanks authored Sep 10, 2021
1 parent 70ac73c commit 228ab5a
Showing 1 changed file with 25 additions and 31 deletions.
56 changes: 25 additions & 31 deletions src/test/lib/ApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,24 +478,10 @@ DummyConnectionCallback(
}

#ifndef QUIC_DISABLE_0RTT_TESTS
static
QUIC_STATUS
AutoShutdownConnectionCallback(
MsQuicConnection* Connection,
void* Context,
QUIC_CONNECTION_EVENT* Event
)
{
if (Event->Type == QUIC_CONNECTION_EVENT_CONNECTED) {
if (Context != nullptr) {
if (!((CxPlatEvent*)Context)->WaitTimeout(1000)) {
TEST_FAILURE("Peer never signaled connected event");
}
}
Connection->Shutdown(0);
}
return QUIC_STATUS_SUCCESS;
}
struct QuicServerSendResumeState {
CxPlatEvent ListenerAcceptEvent;
CxPlatEvent HandshakeCompleteEvent;
};

static
_Function_class_(QUIC_CONNECTION_CALLBACK)
Expand All @@ -520,7 +506,7 @@ ResumptionFailConnectionCallback(
QUIC_STATUS_INVALID_STATE,
Status);
}
CxPlatEventSet(*(CXPLAT_EVENT*)Context);
((QuicServerSendResumeState*)Context)->HandshakeCompleteEvent.Set();
return QUIC_STATUS_SUCCESS;
} else if (Event->Type == QUIC_CONNECTION_EVENT_SHUTDOWN_COMPLETE) {
MsQuic->ConnectionClose(Connection);
Expand All @@ -533,7 +519,7 @@ _Function_class_(NEW_CONNECTION_CALLBACK)
static
bool
ListenerFailSendResumeCallback(
_In_ TestListener* Listener,
_In_ TestListener* Listener,
_In_ HQUIC ConnectionHandle
)
{
Expand All @@ -554,18 +540,21 @@ ListenerFailSendResumeCallback(
return false;
}
MsQuic->SetCallbackHandler(ConnectionHandle, (void*)ResumptionFailConnectionCallback, Listener->Context);
CxPlatEventSet(*(CXPLAT_EVENT*)Listener->Context);
((QuicServerSendResumeState*)Listener->Context)->ListenerAcceptEvent.Set();
return true;
}
#endif

void QuicTestValidateConnection()
{
MsQuicRegistration Registration;
MsQuicRegistration Registration(true);
TEST_TRUE(Registration.IsValid());

MsQuicAlpn Alpn("MsQuicTest");

MsQuicConfiguration ServerConfigurationNoResumption(Registration, Alpn, ServerSelfSignedCredConfig);
TEST_TRUE(ServerConfigurationNoResumption.IsValid());

MsQuicSettings Settings;
Settings.SetServerResumptionLevel(QUIC_SERVER_RESUME_ONLY);
MsQuicConfiguration ServerConfiguration(Registration, Alpn, Settings, ServerSelfSignedCredConfig);
Expand Down Expand Up @@ -939,47 +928,52 @@ void QuicTestValidateConnection()
//
#ifndef QUIC_DISABLE_0RTT_TESTS
{
TestListener MyListener(Registration, ListenerFailSendResumeCallback, ServerConfiguration);
TestListener MyListener(Registration, ListenerFailSendResumeCallback, ServerConfigurationNoResumption);
TEST_TRUE(MyListener.IsValid());

TEST_QUIC_SUCCEEDED(MyListener.Start(Alpn, Alpn.Length()));
QuicAddr ServerLocalAddr;
TEST_QUIC_SUCCEEDED(MyListener.GetLocalAddr(ServerLocalAddr));

CxPlatEvent Event;
MyListener.Context = &Event;
QuicServerSendResumeState ListenerContext;
MyListener.Context = &ListenerContext;

{
//
// Validate that the resumption ticket call fails in the listener.
//
{
MsQuicConnection Connection(Registration, CleanUpManual, AutoShutdownConnectionCallback);
TestScopeLogger logScope("SendResumption in Listener callback");
MsQuicConnection Connection(Registration);
TEST_QUIC_SUCCEEDED(Connection.GetInitStatus());
TEST_QUIC_SUCCEEDED(Connection.StartLocalhost(ClientConfiguration, ServerLocalAddr));
TEST_TRUE(Event.WaitTimeout(1000));
TEST_TRUE(ListenerContext.ListenerAcceptEvent.WaitTimeout(1000));
}

//
// Ensure sending a resumption ticket fails even when connected
// because resumption is not enabled.
//
{
MsQuicConnection Connection(Registration, CleanUpManual, AutoShutdownConnectionCallback, &Event);
TestScopeLogger logScope("SendResumption with resumption disabled");
MsQuicConnection Connection(Registration);
TEST_QUIC_SUCCEEDED(Connection.GetInitStatus());
TEST_QUIC_SUCCEEDED(Connection.StartLocalhost(ClientConfiguration, ServerLocalAddr));
TEST_TRUE(Event.WaitTimeout(1000));
TEST_TRUE(ListenerContext.ListenerAcceptEvent.WaitTimeout(1000));
TEST_TRUE(ListenerContext.HandshakeCompleteEvent.WaitTimeout(1000)); // Wait for server to get connected
}

//
// Enable resumption but ensure failure because the connection
// isn't in connected state yet.
//
{
MsQuicConnection Connection(Registration, CleanUpManual, AutoShutdownConnectionCallback);
TestScopeLogger logScope("SendResumption handshake not complete");
MsQuicConnection Connection(Registration);
TEST_QUIC_SUCCEEDED(Connection.GetInitStatus());
TEST_QUIC_SUCCEEDED(Connection.StartLocalhost(ClientConfiguration, ServerLocalAddr));
TEST_TRUE(Event.WaitTimeout(1000));
TEST_TRUE(ListenerContext.ListenerAcceptEvent.WaitTimeout(1000));
TEST_TRUE(Connection.HandshakeCompleteEvent.WaitTimeout(1000)); // Wait for client to get connected

//
// TODO: add test case to validate ConnectionSendResumptionTicket:
Expand Down

0 comments on commit 228ab5a

Please sign in to comment.