Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Commit

Permalink
Fixed another unit test for subscribing to GENA events
Browse files Browse the repository at this point in the history
It was failing because we were trying to send out our variable notifications
before responding to the subscribe request. I also reduced the time to wait for
variable updates after unsubscribing to 10 seconds instead of 30 because it
seemed very excessive.
  • Loading branch information
stbrowne authored and alexkay committed Jan 18, 2012
1 parent f7bda06 commit 1f88069
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/Mono.Upnp/Mono.Upnp/Mono.Upnp.Internal/EventServer.cs
Expand Up @@ -235,6 +235,13 @@ void Subscribe (HttpListenerContext context, string callback)
Log.Information (string.Format (
"{0} from {1} subscribed to {2} as {3}.",
subscriber.Callback, context.Request.RemoteEndPoint, context.Request.Url, subscriber.Sid));

// NOTE: This will cause an exception in UpnpServer when it tries to close the OutputStream
// I think we should be ok just closing the response and it should handle closing the OutputStream, but not sure
// We have to finish responding with our previous context otherwise the updates don't mean anything to the client
// The client won't have an SID so it won't make sense to publish the updates yet
context.Response.OutputStream.Close();
context.Response.Close();

PublishUpdates (subscriber, state_variables);
}
Expand Down
15 changes: 12 additions & 3 deletions src/Mono.Upnp/Mono.Upnp/Mono.Upnp.Internal/UpnpServer.cs
Expand Up @@ -55,9 +55,18 @@ void OnGetContext (IAsyncResult asyncResult)
}
var context = listener.EndGetContext (asyncResult);
HandleContext (context);
// FIXME this is a bug in Mono
context.Response.OutputStream.Close ();
context.Response.Close ();

try
{
// FIXME this is a bug in Mono
context.Response.OutputStream.Close();
context.Response.Close();
}
catch (ObjectDisposedException)
{
// If we already completed the context in HandleContext we may get this exception, just ignore it...
}

listener.BeginGetContext (OnGetContext, null);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Mono.Upnp.Tests/ServerTests.cs
Expand Up @@ -285,7 +285,7 @@ public void UnsubscribeUnicastEventTest ()
Assert.IsNotNull (response.Headers["SID"]);
sid = response.Headers["SID"];
}
if (Monitor.Wait (mutex, TimeSpan.FromSeconds (30))) {
if (Monitor.Wait (mutex, TimeSpan.FromSeconds (10))) {
Assert.Fail ("The event server sent updates to an unsubscribed client.");
}
}
Expand Down

0 comments on commit 1f88069

Please sign in to comment.