Hello, regarding HIV, masturbation is not considered a risky activity, there are no reports of people getting HIV by doing what you did, even in presence of semen. According to doctors and epidemiologists HIV is only transmitted by unprotected vaginal or anal penetrative sex, sharing needles or mother to child.
However if you want to get tested, third and fourth gen Elisa tests are among the most common ones nowadays, according to CDC, any HIV test is conclusive if taken 12 weeks after an exposure, but you can take them before that, 3rd gen will give you an excellent indicator about your status around 6 - 8 weeks after exposure and 4th gen 4 - 6 weeks after exposure.
I forgot to add how long should I wait until I get tested for this situation