description = "In most cases testing channels is not necessary. You can easily wrap the functionalityunder test in a function and test that. Sometimes, however, you really need to validatethat those channels behave the way you want."
slug = "synchronize-goroutines-in-your-tests"
+++
I have been working on an [emulator for the MOS 6502 Microprocessor, written in Go][1]. As
part of this package I have also implemented a minimal 6551 Asynchronous Communication Interface
Adapter. The 6551 provides serial IO and is easy to use in combination with the 6502.
When the microprocessor writes a byte to the 6551 it is stored in the `tx` (transmit) register
where it's available for other hardware components to read.
In order to make my emulator available using websockets (more on that in a later post), I had
to _know_ when a new byte became available. In a real hardware design I'd probably have to use
the \CTS (Clear to Send) input pin to signal the 6551 I'm ready to read the next byte of data.
But, my goal is to emulate the _Microprocessor_ not a complete computer hardware design.o
The logical option in Go would be to use a channel that receives new bytes when they are