The word "drug test" means different things at different times. It might mean:
- testing your blood, breath, or the like to see if you are under the influence right now
- testing your hair or urine to see if you have used recently
- testing your possessions and person (eg swabbing your hands and bag) for residues
- testing mysterious bags of powder found in your bag to see what you're smuggling
All of these could be called "a random test" and it's clear you're worried about the second one, but it's the least likely of the bunch. The first and third are generally done to have a reason to search your bags super thoroughly. You might be chosen randomly, or because of the origin of your flight, or the clothes you're wearing, or for some other reason that makes sense to the person choosing even if not to anyone else. Then they screen a little further (literally just smell you, maybe ask you some things) and possibly start in on a thorough search if they are suspicious. But being searched isn't the same as being sent home or being arrested.
An aside: these tests may be done at the airport but they are not done by the airport, rather by border officers employed by the country you are entering. Security does some hand-and-bag swabbing too, but that is for explosives, not drugs.
If you are not smuggling (and half a forgotten joint in a jacket pocket in your suitcase might be considered smuggling in some cases) then these tests should not worry you. I watch Border Security and people can smell like pot, can have pot paraphernalia with them, can tell the officers they smoked an hour ago, and are still let in with minimal delay. As long as they are not bringing any. (It being an accident and you not meaning to are not accepted, you have to truly truly not be bringing any.)
Only one place in the world does blood tests to check for prior use: Singapore. And they don't test visitors, only citizens and permanent residents who are returning. Further, they warn about it:

(From https://www.channelnewsasia.com/singapore/changi-airport-drug-check-enforcement-traveller-thailand-cannabis-2957591 which has more details.)
Bottom line: don't bring any pot across borders, or any cannabis related products like edibles. While there is a small chance some sort of testing will occur (someone smelling you, or swabbing something), it will not be intrusive and the strongest consequence these tests can have is a thorough search. The search may delay you, embarrass you, worry you and those waiting for you, but if you do not have any cannabis with you, that is all that will happen. The search will come up empty and you will be on your way, with a story to tell about "that time I got randomly tested in [country]".