1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- from tests .integration import use_singledc
16-
1715try :
1816 import unittest2 as unittest
1917except ImportError :
2018 import unittest # noqa
2119
22- from cassandra .cluster import Cluster , ExecutionProfile
23- from cassandra .policies import HostFilterPolicy , RoundRobinPolicy , SimpleConvictionPolicy , WhiteListRoundRobinPolicy
20+ from cassandra .cluster import Cluster , ExecutionProfile , ResponseFuture
21+ from cassandra .policies import HostFilterPolicy , RoundRobinPolicy , SimpleConvictionPolicy , \
22+ WhiteListRoundRobinPolicy , ConstantSpeculativeExecutionPolicy
2423from cassandra .pool import Host
24+ from cassandra .query import SimpleStatement
2525
2626from tests .integration import PROTOCOL_VERSION , local
27+ from tests .integration import use_singledc
2728
29+ from unittest .mock import patch
2830from concurrent .futures import wait as wait_futures
29-
31+ from itertools import count
3032
3133def setup_module ():
3234 use_singledc ()
@@ -36,7 +38,7 @@ class HostFilterPolicyTests(unittest.TestCase):
3638
3739 def test_predicate_changes (self ):
3840 """
39- Test to validate hostfilter reacts correctly when the predicate return
41+ Test to validate host filter reacts correctly when the predicate return
4042 a different subset of the hosts
4143 HostFilterPolicy
4244 @since 3.8
@@ -91,3 +93,30 @@ def test_only_connects_to_subset(self):
9193 queried_hosts .update (response .response_future .attempted_hosts )
9294 queried_hosts = set (host .address for host in queried_hosts )
9395 self .assertEqual (queried_hosts , only_connect_hosts )
96+
97+
98+ class SpeculativeExecutionPolicy (unittest .TestCase ):
99+ def test_delay_can_be_0 (self ):
100+ """
101+ Test to validate that the delay can be zero for the ConstantSpeculativeExecutionPolicy
102+ @since 3.13
103+ @jira_ticket PYTHON-836
104+ @expected_result all the queries are executed immediately
105+ @test_category policy
106+ """
107+ number_of_requests = 6
108+ spec = ExecutionProfile (speculative_execution_policy = ConstantSpeculativeExecutionPolicy (0 , number_of_requests ))
109+
110+ cluster = Cluster ()
111+ cluster .add_execution_profile ("spec" , spec )
112+ session = cluster .connect (wait_for_all_pools = True )
113+ self .addCleanup (cluster .shutdown )
114+
115+ with patch .object (ResponseFuture , "_on_speculative_execute" ,
116+ side_effect = ResponseFuture ._on_speculative_execute ,
117+ autospec = True ) as on_speculative_mocked :
118+ stmt = SimpleStatement ("INSERT INTO test3rf.test(k, v) VALUES (1, 2)" )
119+ stmt .is_idempotent = True
120+ results = session .execute (stmt , execution_profile = "spec" )
121+ self .assertEqual (len (results .response_future .attempted_hosts ), 3 )
122+ self .assertEqual (on_speculative_mocked .call_count , number_of_requests )
0 commit comments