Fix tests for EOF
Clean up EOF handling and do not send signals to subprocess directly
Add more explicit EOF check