I hear it often repeated (sorry, no source) that leadership only allows a bill to be voted upon after they know they have the votes to pass it. Otherwise it would be a waste of time. Frequently, when a consequential bill is being considered, there is a lot of reporting on ensuring that a bill has the votes. I remember this process taking a considerable amount of time when the Democrats tried to pass the ACA. Presumably that is why Speaker Ryan pulled the AHCA from consideration without a vote a few months ago, they couldn't line up the votes.
Yet, in the last few weeks the Senate has now held several votes on replacing or repealing the ACA where, at least to the public it appeared they did not have much chance of passing, and indeed they did fail. Moreover, after the first bill failed, they tried voting on a few slightly different bills to see if they worked, and they didn't!
Why does leadership sometimes work to ensure passage before a vote is held and sometimes just vote and vote again?