@@ -44,7 +44,7 @@ import (
4444 "time"
4545 "unicode"
4646
47- inf "gopkg.in/inf.v0"
47+ "gopkg.in/inf.v0"
4848
4949 "github.com/stretchr/testify/require"
5050)
@@ -3955,3 +3955,46 @@ func TestRoutingKeyCacheUsesOverriddenKeyspace(t *testing.T) {
39553955
39563956 session .Query ("DROP KEYSPACE IF EXISTS gocql_test_routing_key_cache" ).Exec ()
39573957}
3958+
3959+ func TestTimeoutOverride (t * testing.T ) {
3960+ session := createSession (t )
3961+ defer session .Close ()
3962+
3963+ if session .cfg .ProtoVersion < 3 {
3964+ t .Skip ("named Values are not supported in protocol < 3" )
3965+ }
3966+
3967+ if err := createTable (session , "CREATE TABLE gocql_test.named_query(id int, value text, PRIMARY KEY (id))" ); err != nil {
3968+ t .Fatal (err )
3969+ }
3970+
3971+ // normal case
3972+ err := session .Query ("INSERT INTO gocql_test.named_query(id, value) VALUES(1, 'value')" ).Exec ()
3973+ if err != nil {
3974+ t .Fatal (err )
3975+ }
3976+
3977+ //decrease Conn.timeout
3978+ session .executor .pool .mu .Lock ()
3979+ for _ , conPool := range session .executor .pool .hostConnPools {
3980+ conPool .mu .Lock ()
3981+ for _ , conn := range conPool .conns {
3982+ conn .r .SetTimeout (50 )
3983+ }
3984+ conPool .mu .Unlock ()
3985+ }
3986+ session .executor .pool .mu .Unlock ()
3987+ err = session .Query ("INSERT INTO gocql_test.named_query(id, value) VALUES(2, 'value')" ).Exec ()
3988+ if err != ErrTimeoutNoResponse {
3989+ t .Fatalf ("expected: ErrTimeoutNoResponse, got: %v" , err )
3990+ }
3991+
3992+ // override timeout with context
3993+ ctx , cancel := context .WithTimeout (context .Background (), 3 * time .Second )
3994+ defer cancel ()
3995+ err = session .Query ("TRUNCATE TABLE gocql_test.named_query" ).WithContext (ctx ).Exec ()
3996+ if err != nil {
3997+ t .Fatal (err )
3998+ }
3999+
4000+ }
0 commit comments