Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Response Exception work #297

Merged
merged 14 commits into from
Jul 13, 2024

Conversation

RobertK66
Copy link
Contributor

What I did:

  • again a lot of refactoring's in the Tests.

    • (first I Suspected the Static TestHelper to be/make some problems. I think I was wrong but did not change back the usage of one instance per test)
    • Made all MediaChannel tests to disconnect in the end. This really helped to stabilize Test results. Now I have deterministic results even with different internet/network timings and device states!
  • the main thing I found was that a LOAD_ERROR never canceled the correct Task waiting for its TaskCompletionSource. The reason was that the 2nd call of TaskCompletionSourceInvoke() did not find the tcs because the 1st call already removed it!
    (unfortunately I can not provoke this with a unittest. It needs my device to be connected to my current HomeAudio Client which tries immediate to reconnect on receiving of a disconnect. This is a synchronized load_App from 2 different clients where my unittest then gets the LOAD_ERROR with reason 'CANCELED'.

  • some adaption of the ChannelLogging. Now also receive Trace is logged on the Channel._logger. I think this is more consistent now

RobertK66 and others added 11 commits July 5, 2024 08:33
make Channel Loggers to pick up the according receive messages.
- got rid of stic TestHelper (didn't really help)
- shutdown client in all Media Channel tests to keep device in idle(?) -> this helped!!!
(really use task completion object to Enter the Exception in await task)
@Tapanila
Copy link
Owner

You are talking here about LOAD_ERROR and then you added a class called LAUNCH_ERROR.
Also the LAUNCH_ERROR could be response to launching an application?

@RobertK66
Copy link
Contributor Author

Yes, sorry its a 'LAUNCH_ERROR'. I read my own wrong commit comment here...

This error happens when 2 different Clients try to make LaunchApplicationAsync with different AppIDs. One gets the expected ChromecastStatus as answer, and the other one - before the fix - never gets an answer and times out on the await.

@RobertK66
Copy link
Contributor Author

RobertK66 commented Jul 12, 2024

Here is a log of this case before the fix. There the other AppID is loaded but normally - if no other client tries to reconnect - the LAUNCH request would be answered with a ChromecastStatus containing the new Application launched. Here the LAUNCH_ERROR never triggers anything and the test timed out (showing status and making ping/pong to the 'old other APPID' ....

After the fix I do get an exception on the await LaunchApplicationAsync, which is the correct thing to have in this case.

1:52:26 HeartbeatChannel Debug Started heartbeat timeout timer
11:52:26 ConnectionChannel Trace SENT    : receiver-0: {"requestId":1232381870,"type":"CONNECT"}
11:52:26 ReceiverChannel Trace SENT    : receiver-0: {"requestId":1232381871,"type":"GET_STATUS"}
11:52:26 HeartbeatChannel Debug Stopped heartbeat timeout timer
11:52:26 ReceiverChannel Trace RECEIVED: {"requestId":1232381871,"status":{"applications":[{"appId":"9B5A75B4","displayName":"Hi-Fi Cast","isIdleScreen":false,"launchedFromCloud":false,"namespaces":[{"name":"urn:x-cast:com.google.cast.debugoverlay"},{"name":"urn:x-cast:com.google.cast.cac"},{"name":"urn:x-cast:com.google.cast.media"}],"sessionId":"26b17e89-f66c-45e7-91e8-8f3fa261a99f","statusText":"Hi-Fi Cast","transportId":"26b17e89-f66c-45e7-91e8-8f3fa261a99f"}],"volume":{"controlType":"master","level":0.2705882489681244,"muted":false,"stepInterval":0.03125}},"type":"RECEIVER_STATUS"}
11:52:26 ReceiverChannel Trace SENT    : receiver-0: {"appId":"B3419EF5","requestId":1232381872,"type":"LAUNCH"}
11:52:26 HeartbeatChannel Debug Stopped heartbeat timeout timer
11:52:26 ReceiverChannel Trace RECEIVED: {"requestId":0,"status":{"volume":{"controlType":"master","level":0.2705882489681244,"muted":false,"stepInterval":0.03125}},"type":"RECEIVER_STATUS"}
11:52:26 HeartbeatChannel Debug Stopped heartbeat timeout timer
11:52:26 ReceiverChannel Trace RECEIVED: {"reason":"CANCELLED","requestId":1232381872,"type":"LAUNCH_ERROR"}
11:52:26 HeartbeatChannel Debug Stopped heartbeat timeout timer
11:52:26 ReceiverChannel Trace RECEIVED: {"requestId":0,"status":{"volume":{"controlType":"master","level":0.2705882489681244,"muted":false,"stepInterval":0.03125}},"type":"RECEIVER_STATUS"}
11:52:27 HeartbeatChannel Debug Stopped heartbeat timeout timer
11:52:27 ReceiverChannel Trace RECEIVED: {"requestId":1310472988,"status":{"applications":[{"appId":"9B5A75B4","displayName":"Hi-Fi Cast","isIdleScreen":false,"launchedFromCloud":false,"namespaces":[{"name":"urn:x-cast:com.google.cast.debugoverlay"},{"name":"urn:x-cast:com.google.cast.cac"},{"name":"urn:x-cast:com.google.cast.media"}],"sessionId":"bd6a9461-8b06-4225-b8df-792b1a6df3fd","statusText":"Hi-Fi Cast","transportId":"bd6a9461-8b06-4225-b8df-792b1a6df3fd"}],"volume":{"controlType":"master","level":0.2705882489681244,"muted":false,"stepInterval":0.03125}},"type":"RECEIVER_STATUS"}
11:52:32 HeartbeatChannel Trace RECEIVED: {"type":"PING"}
11:52:32 HeartbeatChannel Debug Received ping message on Heartbeat channel
11:52:32 HeartbeatChannel Trace SENT    : receiver-0: {"type":"PONG"}
11:52:32 HeartbeatChannel Debug Sent pong message on Heartbeat channel
11:52:38 HeartbeatChannel Trace RECEIVED: {"type":"PING"}
11:52:38 HeartbeatChannel Debug Received ping message on Heartbeat channel
11:52:38 HeartbeatChannel Trace SENT    : receiver-0: {"type":"PONG"}
11:52:38 HeartbeatChannel Debug Sent pong message on Heartbeat channel
11:52:43 HeartbeatChannel Trace RECEIVED: {"type":"PING"}
11:52:43 HeartbeatChannel Debug Received ping message on Heartbeat channel
11:52:43 HeartbeatChannel Trace SENT    : receiver-0: {"type":"PONG"}
11:52:43 HeartbeatChannel Debug Sent pong message on Heartbeat channel
11:52:48 HeartbeatChannel Trace RECEIVED: {"type":"PING"}
11:52:48 HeartbeatChannel Debug Received ping message on Heartbeat channel
11:52:48 HeartbeatChannel Trace SENT    : receiver-0: {"type":"PONG"}
11:52:48 HeartbeatChannel Debug Sent pong message on Heartbeat channel
11:52:53 HeartbeatChannel Trace RECEIVED: {"type":"PING"}
11:52:53 HeartbeatChannel Debug Received ping message on Heartbeat channel
11:52:53 HeartbeatChannel Trace SENT    : receiver-0: {"type":"PONG"}
11:52:53 HeartbeatChannel Debug Sent pong message on Heartbeat channel

@Tapanila
Copy link
Owner

Thanks for the reply. Now it makes sense and it's great to get those error cases fixed. I noticed that there wasn't any logic to handle load media errors either when researching on this.

Can you resolve the conflicts. I will merge this after that and release a new version.

@RobertK66
Copy link
Contributor Author

RobertK66 commented Jul 12, 2024

What I am not sure now is if the channel logic is consistent now. On the receiver Channel I was perfectly happy with the 'Cannot cast received message X to expected message Y Exception' generated by the receive loop. I did not really dive into all of the inheritance with the "StatusChannel"s vs "normal channels".
I think end of the day for the client the only important thing is to get the(any) Exception and not run into useless timeout.

@Tapanila
Copy link
Owner

I agree with that. Also since there is very minimal documentation the most important thing is that there is test case showing it. So I'm very happy with the current status

@Tapanila Tapanila merged commit b74f52f into Tapanila:main Jul 13, 2024
1 check passed
@RobertK66 RobertK66 deleted the feature/AnotherTryToStabilize branch July 13, 2024 14:15
@RobertK66
Copy link
Contributor Author

Ok, I think this code is good to go. I checked it with a local built package and all my applications (with and without Logging) work like a charm ...

@Tapanila
Copy link
Owner

Are your applications open source? I was finally planning to write a new sample application and thinking a bit of what I would like to do with it

@RobertK66
Copy link
Contributor Author

I do them in a public repos here: https://github.com/RobertK66/HomeAudio , but it is far more undocumented than your code here and I am not really prepared to give a lot of support over there.

This is more of a playground for me to experiment with stuff ( Win UI3 - sort of works/ Consolen GUI . thats it / Avalon not anything coded there / ... ) at this time. The ConGui Project there is the one that serves my home office/JBL Speaker since i abandoned my first WPF implementation after years of using that (I think this was available open source somewhen in my fork of your sharpcaster repos years ago....)

@Tapanila
Copy link
Owner

Thanks for the link. I will take a look at AvaloniaUI and probably create a sample using it since I haven't done anything with it yet and it seems nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants