You should instead use the time to optimize your program or tools until these distractions cede.
Ultimately, you want to test your software until it yields the expected results, either by passing all tests or by returning results of a measurement for example. But sometimes, your initially designed software architecture or test set or tools don’t live up to the challenge. By this time tour program has become complex enough that it takes a while to run all the tests or to measure all your data.
And during this time the distraction devil sneaks in and wastes your time. When what you actually want to do is use that time to improve your actual measurement or evaluate the data and think about what else you would want to measure.
Therefore, you should instead work on refactoring your software, your tests or improve on your tools. I have the impression the part of a programmer’s work from which interesting open source tools emerge (e.g. editor plug-ins).
Whenever you catch yourself idling (i.e. reading random stuff on the Internet in time slots which are not designated to this) then think about (and feel) where your own software or tools are limiting you. Start from scratch, improve on your tools or refactor your software until it does exactly what you need it to do.
If you’re too tired to do any of this then take a break or do something that distracts your mind from this problem for a while. But do not sit in front of the computer pretending you’re working on a problem when actually that problem has defeated you and you’re escaping the truth by facing some random distraction instead of the venue of the war. Release the pause button, get back in and fight 😉