If the condom was stuck but there as they exited your anus, you were likely fine. The head of their penis is all that needs to be covered for your protection which is normally the case when a condom becomes 'stuck'
If you're not sure what happened, and you want to test, you should just go ahead and test for peace of mind. There's no point in asking "what if" questions since we weren't there and can't guess what happened.
4th generation test (also known as the Ag/Ab test), you can take at 28 days post-event.
Any other test can be taken 90 days or more after the event for a conclusive result.