agent: Fix assertion in cockpit_resource_finalize()

The close virtual method was not being called if the transport
closed before the channel.

Add a test which double checks this problem.

Fixes #1104
Closes #1105
Reviewed-by: Marius Vollmer <marius.vollmer@redhat.com>