github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/test/benchmarks/tools/redis_test.go (about) 1 // Copyright 2020 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package tools 16 17 import ( 18 "testing" 19 ) 20 21 // TestRedis checks the Redis parsers on sample output. 22 func TestRedis(t *testing.T) { 23 sampleData := ` 24 "PING_INLINE","48661.80" 25 "PING_BULK","50301.81" 26 "SET","48923.68" 27 "GET","49382.71" 28 "INCR","49975.02" 29 "LPUSH","49875.31" 30 "RPUSH","50276.52" 31 "LPOP","50327.12" 32 "RPOP","50556.12" 33 "SADD","49504.95" 34 "HSET","49504.95" 35 "SPOP","50025.02" 36 "LPUSH (needed to benchmark LRANGE)","48875.86" 37 "LRANGE_100 (first 100 elements)","33955.86" 38 "LRANGE_300 (first 300 elements)","16550.81"// Copyright 2020 The gVisor Authors. 39 // 40 // Licensed under the Apache License, Version 2.0 (the "License"); 41 // you may not use this file except in compliance with the License. 42 // You may obtain a copy of the License at 43 // 44 // http://www.apache.org/licenses/LICENSE-2.0 45 // 46 // Unless required by applicable law or agreed to in writing, software 47 // distributed under the License is distributed on an "AS IS" BASIS, 48 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 // See the License for the specific language governing permissions and 50 // limitations under the License. 51 52 package tools 53 54 "LRANGE_500 (first 450 elements)","13653.74" 55 "LRANGE_600 (first 600 elements)","11219.57" 56 "MSET (10 keys)","44682.75" 57 ` 58 wants := map[string]float64{ 59 "PING_INLINE": 48661.80, 60 "PING_BULK": 50301.81, 61 "SET": 48923.68, 62 "GET": 49382.71, 63 "INCR": 49975.02, 64 "LPUSH": 49875.31, 65 "RPUSH": 50276.52, 66 "LPOP": 50327.12, 67 "RPOP": 50556.12, 68 "SADD": 49504.95, 69 "HSET": 49504.95, 70 "SPOP": 50025.02, 71 "LRANGE_100": 33955.86, 72 "LRANGE_300": 16550.81, 73 "LRANGE_500": 13653.74, 74 "LRANGE_600": 11219.57, 75 "MSET": 44682.75, 76 } 77 for op, want := range wants { 78 redis := Redis{ 79 Operation: op, 80 } 81 if got, err := redis.parseOperation(sampleData); err != nil { 82 t.Fatalf("failed to parse %s: %v", op, err) 83 } else if want != got { 84 t.Fatalf("wanted %f for op %s, got %f", want, op, got) 85 } 86 } 87 }