improve test code
Use a counter instead of time for blink count; remove race condition in unit test