A quick search shows that many states have changed their stances either through precedent or legislation over the past 20 years or so, so my information may be out of date.
The California court's website states that cohabiting spouses is a conclusive presumption[1] and the exceptions to overturning are very limited, even with genetic testing. I'm not a lawyer and can't easily research precedent, but the law seems pretty clear that if you don't challenge before the 2nd birthday of the child, it can't be overturned. There may be other restrictions as well.
It seems like recent anecdotes I can find relate to the 2 year deadline. The father didn't challenge paternity at the time of divorce, found out he was not biological father (or that he could challenge) later, but it was too late.
Hopefully we can all agree it would be shitty to disown a kid you've been raising for years because you found out you weren't the biological father, but I can certainly have empathy for someone who has limited (or no) visitation and is stuck shelling out money for someone else's kid.
[edit]
It looks like the law was revised recently as well, so amybe the court website is out of date on some of this? AB2684 mentions "rebuttable presumptions" and was passed in 2018, going into effect in 2019. IANAL and don't have time to follow up on this.
1: https://www.courts.ca.gov/1202.htm