def METHOD_NAME(workflow):
    reserved_build_id = 1
    mock_reactor_config(workflow)
    # Mark the build is successful.
    MockEnv(workflow).mock_build_outcome(failed=False)
    workflow.data.reserved_token = "1234"
    workflow.data.reserved_build_id = reserved_build_id
    class _MockClientSession(MockClientSession):
        def getBuild(self, *args, **kwargs):
            return {"state": koji.BUILD_STATES["BUILDING"]}
        def CGRefundBuild(self, cg, build_id, token, state):
            assert PROG == cg
            assert workflow.data.reserved_token == token
            assert workflow.data.reserved_build_id == build_id
            assert koji.BUILD_STATES["FAILED"] == state
    flexmock(koji).should_receive("ClientSession").and_return(_MockClientSession())
    plugin = CancelBuildReservation(workflow)
    expected_msg = f"but the reserved build {reserved_build_id} is in state BUILDING"
    with pytest.raises(RuntimeError, match=expected_msg):
        plugin.run()