|
| 1 | +varnishtest "Tests easy_execution timeout" |
| 2 | + |
| 3 | +server s1 { |
| 4 | + rxreq |
| 5 | + txresp |
| 6 | +} -repeat 1 -start |
| 7 | + |
| 8 | +varnish v1 -arg "-p vsl_reclen=1024" -vcl+backend { |
| 9 | + import ${vmod_redis}; |
| 10 | + |
| 11 | + sub vcl_init { |
| 12 | + redis.subnets( |
| 13 | + masks={""}); |
| 14 | + |
| 15 | + redis.sentinels( |
| 16 | + locations={""}, |
| 17 | + period=0, |
| 18 | + connection_timeout=500, |
| 19 | + command_timeout=0); |
| 20 | + |
| 21 | + new db = redis.db( |
| 22 | + location="${redis_master1_ip}:${redis_master1_port}", |
| 23 | + type=master, |
| 24 | + connection_timeout=500, |
| 25 | + connection_ttl=0, |
| 26 | + command_timeout=0, |
| 27 | + max_command_retries=0, |
| 28 | + shared_connections=false, |
| 29 | + max_connections=1, |
| 30 | + password="", |
| 31 | + sickness_ttl=0, |
| 32 | + ignore_slaves=false, |
| 33 | + max_cluster_hops=0); |
| 34 | + } |
| 35 | + |
| 36 | + sub vcl_deliver { |
| 37 | + # Fast command (no timeout). |
| 38 | + db.easy_execute("SET", "foo", "hello", master = true); |
| 39 | + set resp.http.Replied-1 = db.replied(); |
| 40 | + set resp.http.Reply-1 = db.get_reply(); |
| 41 | + |
| 42 | + # Slow command (no timeout). |
| 43 | + db.easy_execute("DEBUG", "sleep", "3", master = true); |
| 44 | + set resp.http.Replied-2 = db.replied(); |
| 45 | + set resp.http.Reply-2 = db.get_reply(); |
| 46 | + |
| 47 | + # Fast command (1000 ms timeout). |
| 48 | + db.easy_execute("SET", "foo", "hello", master = true, timeout = 1000); |
| 49 | + set resp.http.Replied-3 = db.replied(); |
| 50 | + set resp.http.Reply-3 = db.get_reply(); |
| 51 | + |
| 52 | + # Slow command (1000 ms timeout). |
| 53 | + db.easy_execute("DEBUG", "sleep", "3", master = true, timeout = 1000); |
| 54 | + set resp.http.Replied-4 = db.replied(); |
| 55 | + set resp.http.Reply-4 = db.get_reply(); |
| 56 | + |
| 57 | + # Fast command (no timeout). |
| 58 | + db.easy_execute("SET", "foo", "hello", master = true); |
| 59 | + set resp.http.Replied-5 = db.replied(); |
| 60 | + set resp.http.Reply-5 = db.get_reply(); |
| 61 | + |
| 62 | + # Slow command (no timeout). |
| 63 | + db.easy_execute("DEBUG", "sleep", "3", master = true); |
| 64 | + set resp.http.Replied-6 = db.replied(); |
| 65 | + set resp.http.Reply-6 = db.get_reply(); |
| 66 | + |
| 67 | + # Stats. |
| 68 | + set resp.http.db-stats = db.stats(); |
| 69 | + set resp.http.db-servers-total = db.counter("servers.total"); |
| 70 | + set resp.http.db-connections-total = db.counter("connections.total"); |
| 71 | + set resp.http.db-connections-dropped-error = db.counter("connections.dropped.error"); |
| 72 | + set resp.http.db-commands-total = db.counter("commands.total"); |
| 73 | + set resp.http.db-commands-error = db.counter("commands.error"); |
| 74 | + set resp.http.db-commands-failed = db.counter("commands.failed"); |
| 75 | + set resp.http.db-commands-noscript = db.counter("commands.noscript"); |
| 76 | + } |
| 77 | +} -start |
| 78 | + |
| 79 | +client c1 { |
| 80 | + txreq |
| 81 | + rxresp |
| 82 | + |
| 83 | + expect resp.http.Replied-1 == "true" |
| 84 | + expect resp.http.Reply-1 == "OK" |
| 85 | + |
| 86 | + expect resp.http.Replied-2 == "true" |
| 87 | + expect resp.http.Reply-2 == "OK" |
| 88 | + |
| 89 | + expect resp.http.Replied-3 == "true" |
| 90 | + expect resp.http.Reply-3 == "OK" |
| 91 | + |
| 92 | + expect resp.http.Replied-4 == "false" |
| 93 | + expect resp.http.Reply-4 == "" |
| 94 | + |
| 95 | + expect resp.http.Replied-5 == "true" |
| 96 | + expect resp.http.Reply-5 == "OK" |
| 97 | + |
| 98 | + expect resp.http.Replied-6 == "true" |
| 99 | + expect resp.http.Reply-6 == "OK" |
| 100 | + |
| 101 | + expect resp.http.db-servers-total == "1" |
| 102 | + expect resp.http.db-connections-total == "2" |
| 103 | + expect resp.http.db-connections-dropped-error == "1" |
| 104 | + expect resp.http.db-commands-total == "5" |
| 105 | + expect resp.http.db-commands-failed == "1" |
| 106 | + expect resp.http.db-commands-error == "0" |
| 107 | + expect resp.http.db-commands-noscript == "0" |
| 108 | +} -run |
| 109 | + |
| 110 | +varnish v1 -expect client_req == 1 |
0 commit comments