@@ -17,6 +17,7 @@ import (
1717 "github.com/cockroachdb/cockroach/pkg/roachpb"
1818 clustersettings "github.com/cockroachdb/cockroach/pkg/settings/cluster"
1919 "github.com/cockroachdb/cockroach/pkg/testutils/datapathutils"
20+ "github.com/cockroachdb/cockroach/pkg/testutils/dd"
2021 "github.com/cockroachdb/cockroach/pkg/util/hlc"
2122 "github.com/cockroachdb/cockroach/pkg/util/leaktest"
2223 "github.com/cockroachdb/cockroach/pkg/util/log"
@@ -64,7 +65,7 @@ func TestStoreLiveness(t *testing.T) {
6465 case "send-heartbeats" :
6566 now := parseTimestamp (t , d , "now" )
6667 manual .AdvanceTo (now .GoTime ())
67- sm .options .SupportDuration = parseDuration (t , d , "support-duration" )
68+ sm .options .SupportDuration = dd . ScanArg [time. Duration ] (t , d , "support-duration" )
6869 sm .maybeAddStores (ctx )
6970 sm .sendHeartbeats (ctx )
7071 heartbeats := sender .drainSentMessages ()
@@ -88,7 +89,7 @@ func TestStoreLiveness(t *testing.T) {
8889
8990 case "restart" :
9091 now := parseTimestamp (t , d , "now" )
91- gracePeriod := parseDuration (t , d , "grace-period" )
92+ gracePeriod := dd . ScanArg [time. Duration ] (t , d , "grace-period" )
9293 o := Options {SupportWithdrawalGracePeriod : gracePeriod }
9394 sm = NewSupportManager (
9495 storeID , engine , o , settings , stopper , clock , nil , & sender , nil ,
@@ -98,8 +99,7 @@ func TestStoreLiveness(t *testing.T) {
9899 return ""
99100
100101 case "error-on-write" :
101- var errorOnWrite bool
102- d .ScanArgs (t , "on" , & errorOnWrite )
102+ errorOnWrite := dd .ScanArg [bool ](t , d , "on" )
103103 engine .SetErrorOnWrite (errorOnWrite )
104104 return ""
105105
@@ -166,31 +166,15 @@ func printMsgs(msgs []slpb.Message) string {
166166func parseStoreID (
167167 t * testing.T , d * datadriven.TestData , nodeStr string , storeStr string ,
168168) slpb.StoreIdent {
169- var nodeID int64
170- d .ScanArgs (t , nodeStr , & nodeID )
171- var storeID int64
172- d .ScanArgs (t , storeStr , & storeID )
173169 return slpb.StoreIdent {
174- NodeID : roachpb .NodeID ( nodeID ),
175- StoreID : roachpb .StoreID ( storeID ),
170+ NodeID : dd . ScanArg [ roachpb.NodeID ]( t , d , nodeStr ),
171+ StoreID : dd . ScanArg [ roachpb.StoreID ]( t , d , storeStr ),
176172 }
177173}
178174
179175func parseTimestamp (t * testing.T , d * datadriven.TestData , name string ) hlc.Timestamp {
180- var wallTimeSecs int64
181- d .ScanArgs (t , name , & wallTimeSecs )
182- wallTime := wallTimeSecs * int64 (time .Second )
183- return hlc.Timestamp {WallTime : wallTime }
184- }
185-
186- func parseDuration (t * testing.T , d * datadriven.TestData , name string ) time.Duration {
187- var durationStr string
188- d .ScanArgs (t , name , & durationStr )
189- duration , err := time .ParseDuration (durationStr )
190- if err != nil {
191- t .Errorf ("can't parse duration %s; error: %v" , durationStr , err )
192- }
193- return duration
176+ wallTimeSecs := dd .ScanArg [int64 ](t , d , name )
177+ return hlc.Timestamp {WallTime : wallTimeSecs * int64 (time .Second )}
194178}
195179
196180func parseMsgs (t * testing.T , d * datadriven.TestData , storeIdent slpb.StoreIdent ) []* slpb.Message {
@@ -205,10 +189,8 @@ func parseMsgs(t *testing.T, d *datadriven.TestData, storeIdent slpb.StoreIdent)
205189 if d .Cmd != "msg" {
206190 d .Fatalf (t , "expected \" msg\" , found %s" , d .Cmd )
207191 }
208- var msgTypeStr string
209- d .ScanArgs (t , "type" , & msgTypeStr )
210192 var msgType slpb.MessageType
211- switch msgTypeStr {
193+ switch msgTypeStr := dd . ScanArg [ string ]( t , d , "type" ); msgTypeStr {
212194 case slpb .MsgHeartbeat .String ():
213195 msgType = slpb .MsgHeartbeat
214196 case slpb .MsgHeartbeatResp .String ():
@@ -217,14 +199,13 @@ func parseMsgs(t *testing.T, d *datadriven.TestData, storeIdent slpb.StoreIdent)
217199 d .Fatalf (t , "unexpected \" type\" , found %s" , msgTypeStr )
218200 }
219201 remoteID := parseStoreID (t , d , "from-node-id" , "from-store-id" )
220- var epoch int64
221- d .ScanArgs (t , "epoch" , & epoch )
202+ epoch := dd .ScanArg [slpb.Epoch ](t , d , "epoch" )
222203 expiration := parseTimestamp (t , d , "expiration" )
223204 msg := & slpb.Message {
224205 Type : msgType ,
225206 From : remoteID ,
226207 To : storeIdent ,
227- Epoch : slpb . Epoch ( epoch ) ,
208+ Epoch : epoch ,
228209 Expiration : expiration ,
229210 }
230211 msgs = append (msgs , msg )
0 commit comments