Its largely preventable if you act with a reasonable level of care. Test the water with a new batch before you use it, even if its just administering a fraction of what you cooked up first. You are unlikely to have such potent stuff that a hundredth of an active dose is giving you an OD. That is unless someone is actively trying to kill you. The equivalent of an allergy test is nothing specific to injecting hard drugs.
Addicts often dont do it since the test dosage is wasted and its extra injection. It becomes especially problematic when money is tight and you buy individual bubbles. But that is the inherent risk you take with street drugs and the care and effort you have to invest to not OD. Its like never sharing anything that goes into your veins. Neither an OD nor catching HIV or Hep-C are cases of just bad luck, they are the result of being reckless and skipping an important and necessary step.