@@ -3410,3 +3410,46 @@ func TestQuery_SetHostID(t *testing.T) {
34103410 t .Fatalf ("Expected error to be: %v, but got %v" , ErrNoConnections , err )
34113411 }
34123412}
3413+
3414+ func TestTimeoutOverride (t * testing.T ) {
3415+ session := createSession (t )
3416+ defer session .Close ()
3417+
3418+ if session .cfg .ProtoVersion < 3 {
3419+ t .Skip ("named Values are not supported in protocol < 3" )
3420+ }
3421+
3422+ if err := createTable (session , "CREATE TABLE gocql_test.named_query(id int, value text, PRIMARY KEY (id))" ); err != nil {
3423+ t .Fatal (err )
3424+ }
3425+
3426+ // normal case
3427+ err := session .Query ("INSERT INTO gocql_test.named_query(id, value) VALUES(1, 'value')" ).Exec ()
3428+ if err != nil {
3429+ t .Fatal (err )
3430+ }
3431+
3432+ //decrease Conn.timeout
3433+ session .executor .pool .mu .Lock ()
3434+ for _ , conPool := range session .executor .pool .hostConnPools {
3435+ conPool .mu .Lock ()
3436+ for _ , conn := range conPool .conns {
3437+ conn .timeout = 50
3438+ }
3439+ conPool .mu .Unlock ()
3440+ }
3441+ session .executor .pool .mu .Unlock ()
3442+ err = session .Query ("INSERT INTO gocql_test.named_query(id, value) VALUES(2, 'value')" ).Exec ()
3443+ if err == nil || err != ErrTimeoutNoResponse {
3444+ t .Fatalf ("expected: ErrTimeoutNoResponse, got: %v" , err )
3445+ }
3446+
3447+ // override timeout with context
3448+ ctx , cancel := context .WithTimeout (context .Background (), 3 * time .Second )
3449+ defer cancel ()
3450+ err = session .Query ("TRUNCATE TABLE gocql_test.named_query" ).WithContext (ctx ).Exec ()
3451+ if err != nil {
3452+ t .Fatal (err )
3453+ }
3454+
3455+ }
0 commit comments