Until muscle tires
A spasm can be fleeting or sustained, depending on what is causing it.
An extreme example is sustained electric shock
will cause spasm as long as the shock lasts. If there is a stimulus, such as a back muscle injury, use of the muscle will cause it to spasm. In this case the spasm will and go. This situation can persist for weeks because in spasming the muscles further injures itself.