Test that resources are cleaned up

  - add test
  - fix event channel leak