Best Gauge code snippet using util.Test
pull_test.go
Source:pull_test.go
...25 digestWaitTime = time.Duration(100) * time.Millisecond26 responseWaitTime = time.Duration(200) * time.Millisecond27}28type messageHook func(interface{})29type pullTestInstance struct {30 msgHooks []messageHook31 peers map[string]*pullTestInstance32 name string33 nextPeerSelection []string34 msgQueue chan interface{}35 lock sync.Mutex36 stopChan chan struct{}37 *PullEngine38}39type helloMsg struct {40 nonce uint6441 source string42}43type digestMsg struct {44 nonce uint6445 digest []string46 source string47}48type reqMsg struct {49 items []string50 nonce uint6451 source string52}53type resMsg struct {54 items []string55 nonce uint6456}57func newPushPullTestInstance(name string, peers map[string]*pullTestInstance) *pullTestInstance {58 inst := &pullTestInstance{59 msgHooks: make([]messageHook, 0),60 peers: peers,61 msgQueue: make(chan interface{}, 100),62 nextPeerSelection: make([]string, 0),63 stopChan: make(chan struct{}, 1),64 name: name,65 }66 inst.PullEngine = NewPullEngine(inst, time.Duration(500)*time.Millisecond)67 peers[name] = inst68 go func() {69 for {70 select {71 case <-inst.stopChan:72 return73 case m := <-inst.msgQueue:74 inst.handleMessage(m)75 break76 }77 }78 }()79 return inst80}81// Used to test the messages one peer sends to another.82// Assert statements should be passed via the messageHook f83func (p *pullTestInstance) hook(f messageHook) {84 p.lock.Lock()85 defer p.lock.Unlock()86 p.msgHooks = append(p.msgHooks, f)87}88func (p *pullTestInstance) handleMessage(m interface{}) {89 p.lock.Lock()90 for _, f := range p.msgHooks {91 f(m)92 }93 p.lock.Unlock()94 if helloMsg, isHello := m.(*helloMsg); isHello {95 p.OnHello(helloMsg.nonce, helloMsg.source)96 return97 }98 if digestMsg, isDigest := m.(*digestMsg); isDigest {99 p.OnDigest(digestMsg.digest, digestMsg.nonce, digestMsg.source)100 return101 }102 if reqMsg, isReq := m.(*reqMsg); isReq {103 p.OnReq(reqMsg.items, reqMsg.nonce, reqMsg.source)104 return105 }106 if resMsg, isRes := m.(*resMsg); isRes {107 p.OnRes(resMsg.items, resMsg.nonce)108 }109}110func (p *pullTestInstance) stop() {111 p.stopChan <- struct{}{}112 p.Stop()113}114func (p *pullTestInstance) setNextPeerSelection(selection []string) {115 p.lock.Lock()116 defer p.lock.Unlock()117 p.nextPeerSelection = selection118}119func (p *pullTestInstance) SelectPeers() []string {120 p.lock.Lock()121 defer p.lock.Unlock()122 return p.nextPeerSelection123}124func (p *pullTestInstance) Hello(dest string, nonce uint64) {125 p.peers[dest].msgQueue <- &helloMsg{nonce: nonce, source: p.name}126}127func (p *pullTestInstance) SendDigest(digest []string, nonce uint64, context interface{}) {128 p.peers[context.(string)].msgQueue <- &digestMsg{source: p.name, nonce: nonce, digest: digest}129}130func (p *pullTestInstance) SendReq(dest string, items []string, nonce uint64) {131 p.peers[dest].msgQueue <- &reqMsg{nonce: nonce, source: p.name, items: items}132}133func (p *pullTestInstance) SendRes(items []string, context interface{}, nonce uint64) {134 p.peers[context.(string)].msgQueue <- &resMsg{items: items, nonce: nonce}135}136func TestPullEngine_Add(t *testing.T) {137 t.Parallel()138 peers := make(map[string]*pullTestInstance)139 inst1 := newPushPullTestInstance("p1", peers)140 defer inst1.Stop()141 inst1.Add("0")142 inst1.Add("0")143 assert.True(t, inst1.PullEngine.state.Exists("0"))144}145func TestPullEngine_Remove(t *testing.T) {146 t.Parallel()147 peers := make(map[string]*pullTestInstance)148 inst1 := newPushPullTestInstance("p1", peers)149 defer inst1.Stop()150 inst1.Add("0")151 assert.True(t, inst1.PullEngine.state.Exists("0"))152 inst1.Remove("0")153 assert.False(t, inst1.PullEngine.state.Exists("0"))154 inst1.Remove("0") // remove twice155 assert.False(t, inst1.PullEngine.state.Exists("0"))156}157func TestPullEngine_Stop(t *testing.T) {158 t.Parallel()159 peers := make(map[string]*pullTestInstance)160 inst1 := newPushPullTestInstance("p1", peers)161 inst2 := newPushPullTestInstance("p2", peers)162 defer inst2.stop()163 inst2.setNextPeerSelection([]string{"p1"})164 go func() {165 for i := 0; i < 100; i++ {166 inst1.Add(string(i))167 time.Sleep(time.Duration(10) * time.Millisecond)168 }169 }()170 time.Sleep(time.Duration(800) * time.Millisecond)171 len1 := len(inst2.state.ToArray())172 inst1.stop()173 time.Sleep(time.Duration(800) * time.Millisecond)174 len2 := len(inst2.state.ToArray())175 assert.Equal(t, len1, len2, "PullEngine was still active after Stop() was invoked!")176}177func TestPullEngineAll2AllWithIncrementalSpawning(t *testing.T) {178 t.Parallel()179 // Scenario: spawn 10 nodes, each 50 ms after the other180 // and have them transfer data between themselves.181 // Expected outcome: obviously, everything should succeed.182 // Isn't that's why we're here?183 instanceCount := 10184 peers := make(map[string]*pullTestInstance)185 for i := 0; i < instanceCount; i++ {186 inst := newPushPullTestInstance(fmt.Sprintf("p%d", i+1), peers)187 inst.Add(string(i + 1))188 time.Sleep(time.Duration(50) * time.Millisecond)189 }190 for i := 0; i < instanceCount; i++ {191 pID := fmt.Sprintf("p%d", i+1)192 peers[pID].setNextPeerSelection(keySet(pID, peers))193 }194 time.Sleep(time.Duration(4000) * time.Millisecond)195 for i := 0; i < instanceCount; i++ {196 pID := fmt.Sprintf("p%d", i+1)197 assert.Equal(t, instanceCount, len(peers[pID].state.ToArray()))198 }199}200func TestPullEngineSelectiveUpdates(t *testing.T) {201 t.Parallel()202 // Scenario: inst1 has {1, 3} and inst2 has {0,1,2,3}.203 // inst1 initiates to inst2204 // Expected outcome: inst1 asks for 0,2 and inst2 sends 0,2 only205 peers := make(map[string]*pullTestInstance)206 inst1 := newPushPullTestInstance("p1", peers)207 inst2 := newPushPullTestInstance("p2", peers)208 defer inst1.stop()209 defer inst2.stop()210 inst1.Add("1", "3")211 inst2.Add("0", "1", "2", "3")212 // Ensure inst2 sent a proper digest to inst1213 inst1.hook(func(m interface{}) {214 if dig, isDig := m.(*digestMsg); isDig {215 assert.True(t, util.IndexInSlice(dig.digest, "0", Strcmp) != -1)216 assert.True(t, util.IndexInSlice(dig.digest, "1", Strcmp) != -1)217 assert.True(t, util.IndexInSlice(dig.digest, "2", Strcmp) != -1)218 assert.True(t, util.IndexInSlice(dig.digest, "3", Strcmp) != -1)219 }220 })221 // Ensure inst1 requested only needed updates from inst2222 inst2.hook(func(m interface{}) {223 if req, isReq := m.(*reqMsg); isReq {224 assert.True(t, util.IndexInSlice(req.items, "1", Strcmp) == -1)225 assert.True(t, util.IndexInSlice(req.items, "3", Strcmp) == -1)226 assert.True(t, util.IndexInSlice(req.items, "0", Strcmp) != -1)227 assert.True(t, util.IndexInSlice(req.items, "2", Strcmp) != -1)228 }229 })230 // Ensure inst1 received only needed updates from inst2231 inst1.hook(func(m interface{}) {232 if res, isRes := m.(*resMsg); isRes {233 assert.True(t, util.IndexInSlice(res.items, "1", Strcmp) == -1)234 assert.True(t, util.IndexInSlice(res.items, "3", Strcmp) == -1)235 assert.True(t, util.IndexInSlice(res.items, "0", Strcmp) != -1)236 assert.True(t, util.IndexInSlice(res.items, "2", Strcmp) != -1)237 }238 })239 inst1.setNextPeerSelection([]string{"p2"})240 time.Sleep(time.Duration(2000) * time.Millisecond)241 assert.Equal(t, len(inst2.state.ToArray()), len(inst1.state.ToArray()))242}243func TestByzantineResponder(t *testing.T) {244 t.Parallel()245 // Scenario: inst1 sends hello to inst2 but inst3 is byzantine so it attempts to send a digest and a response to inst1.246 // expected outcome is for inst1 not to process updates from inst3.247 peers := make(map[string]*pullTestInstance)248 inst1 := newPushPullTestInstance("p1", peers)249 inst2 := newPushPullTestInstance("p2", peers)250 inst3 := newPushPullTestInstance("p3", peers)251 defer inst1.stop()252 defer inst2.stop()253 defer inst3.stop()254 receivedDigestFromInst3 := int32(0)255 inst2.Add("1", "2", "3")256 inst3.Add("1", "6", "7")257 inst2.hook(func(m interface{}) {258 if _, isHello := m.(*helloMsg); isHello {259 inst3.SendDigest([]string{"5", "6", "7"}, 0, "p1")260 }261 })262 inst1.hook(func(m interface{}) {263 if dig, isDig := m.(*digestMsg); isDig {264 if dig.source == "p3" {265 atomic.StoreInt32(&receivedDigestFromInst3, int32(1))266 time.AfterFunc(time.Duration(150)*time.Millisecond, func() {267 inst3.SendRes([]string{"5", "6", "7"}, "p1", 0)268 })269 }270 }271 if res, isRes := m.(*resMsg); isRes {272 // the response is from p3273 if util.IndexInSlice(res.items, "6", Strcmp) != -1 {274 // inst1 is currently accepting responses275 assert.Equal(t, int32(1), atomic.LoadInt32(&(inst1.acceptingResponses)), "inst1 is not accepting digests")276 }277 }278 })279 inst1.setNextPeerSelection([]string{"p2"})280 time.Sleep(time.Duration(1000) * time.Millisecond)281 assert.Equal(t, int32(1), atomic.LoadInt32(&receivedDigestFromInst3), "inst1 hasn't received a digest from inst3")282 assert.True(t, util.IndexInSlice(inst1.state.ToArray(), "1", Strcmp) != -1)283 assert.True(t, util.IndexInSlice(inst1.state.ToArray(), "2", Strcmp) != -1)284 assert.True(t, util.IndexInSlice(inst1.state.ToArray(), "3", Strcmp) != -1)285 assert.True(t, util.IndexInSlice(inst1.state.ToArray(), "5", Strcmp) == -1)286 assert.True(t, util.IndexInSlice(inst1.state.ToArray(), "6", Strcmp) == -1)287 assert.True(t, util.IndexInSlice(inst1.state.ToArray(), "7", Strcmp) == -1)288}289func TestMultipleInitiators(t *testing.T) {290 t.Parallel()291 // Scenario: inst1, inst2 and inst3 both start protocol with inst4 at the same time.292 // Expected outcome: inst4 successfully transfers state to all of them293 peers := make(map[string]*pullTestInstance)294 inst1 := newPushPullTestInstance("p1", peers)295 inst2 := newPushPullTestInstance("p2", peers)296 inst3 := newPushPullTestInstance("p3", peers)297 inst4 := newPushPullTestInstance("p4", peers)298 defer inst1.stop()299 defer inst2.stop()300 defer inst3.stop()301 defer inst4.stop()302 inst4.Add("1", "2", "3", "4")303 inst1.setNextPeerSelection([]string{"p4"})304 inst2.setNextPeerSelection([]string{"p4"})305 inst3.setNextPeerSelection([]string{"p4"})306 time.Sleep(time.Duration(2000) * time.Millisecond)307 for _, inst := range []*pullTestInstance{inst1, inst2, inst3} {308 assert.True(t, util.IndexInSlice(inst.state.ToArray(), "1", Strcmp) != -1)309 assert.True(t, util.IndexInSlice(inst.state.ToArray(), "2", Strcmp) != -1)310 assert.True(t, util.IndexInSlice(inst.state.ToArray(), "3", Strcmp) != -1)311 assert.True(t, util.IndexInSlice(inst.state.ToArray(), "4", Strcmp) != -1)312 }313}314func TestLatePeers(t *testing.T) {315 t.Parallel()316 // Scenario: inst1 initiates to inst2 (items: {1,2,3,4}) and inst3 (items: {5,6,7,8}),317 // but inst2 is too slow to respond, and all items318 // should be received from inst3.319 peers := make(map[string]*pullTestInstance)320 inst1 := newPushPullTestInstance("p1", peers)321 inst2 := newPushPullTestInstance("p2", peers)322 inst3 := newPushPullTestInstance("p3", peers)323 defer inst1.stop()324 defer inst2.stop()325 defer inst3.stop()326 inst2.Add("1", "2", "3", "4")327 inst3.Add("5", "6", "7", "8")328 inst2.hook(func(m interface{}) {329 time.Sleep(time.Duration(600) * time.Millisecond)330 })331 inst1.setNextPeerSelection([]string{"p2", "p3"})332 time.Sleep(time.Duration(2000) * time.Millisecond)333 assert.True(t, util.IndexInSlice(inst1.state.ToArray(), "1", Strcmp) == -1)334 assert.True(t, util.IndexInSlice(inst1.state.ToArray(), "2", Strcmp) == -1)335 assert.True(t, util.IndexInSlice(inst1.state.ToArray(), "3", Strcmp) == -1)336 assert.True(t, util.IndexInSlice(inst1.state.ToArray(), "4", Strcmp) == -1)337 assert.True(t, util.IndexInSlice(inst1.state.ToArray(), "5", Strcmp) != -1)338 assert.True(t, util.IndexInSlice(inst1.state.ToArray(), "6", Strcmp) != -1)339 assert.True(t, util.IndexInSlice(inst1.state.ToArray(), "7", Strcmp) != -1)340 assert.True(t, util.IndexInSlice(inst1.state.ToArray(), "8", Strcmp) != -1)341}342func TestBiDiUpdates(t *testing.T) {343 t.Parallel()344 // Scenario: inst1 has {1, 3} and inst2 has {0,2} and both initiate to the other at the same time.345 // Expected outcome: both have {0,1,2,3} in the end346 peers := make(map[string]*pullTestInstance)347 inst1 := newPushPullTestInstance("p1", peers)348 inst2 := newPushPullTestInstance("p2", peers)349 defer inst1.stop()350 defer inst2.stop()351 inst1.Add("1", "3")352 inst2.Add("0", "2")353 inst1.setNextPeerSelection([]string{"p2"})354 inst2.setNextPeerSelection([]string{"p1"})355 time.Sleep(time.Duration(2000) * time.Millisecond)356 assert.True(t, util.IndexInSlice(inst1.state.ToArray(), "0", Strcmp) != -1)357 assert.True(t, util.IndexInSlice(inst1.state.ToArray(), "1", Strcmp) != -1)358 assert.True(t, util.IndexInSlice(inst1.state.ToArray(), "2", Strcmp) != -1)359 assert.True(t, util.IndexInSlice(inst1.state.ToArray(), "3", Strcmp) != -1)360 assert.True(t, util.IndexInSlice(inst2.state.ToArray(), "0", Strcmp) != -1)361 assert.True(t, util.IndexInSlice(inst2.state.ToArray(), "1", Strcmp) != -1)362 assert.True(t, util.IndexInSlice(inst2.state.ToArray(), "2", Strcmp) != -1)363 assert.True(t, util.IndexInSlice(inst2.state.ToArray(), "3", Strcmp) != -1)364}365func TestSpread(t *testing.T) {366 t.Parallel()367 // Scenario: inst1 initiates to inst2, inst3 inst4 and each have items 0-100. inst5 also has the same items but isn't selected368 // Expected outcome: each responder (inst2, inst3 and inst4) is chosen at least once (the probability for not choosing each of them is slim)369 // inst5 isn't selected at all370 peers := make(map[string]*pullTestInstance)371 inst1 := newPushPullTestInstance("p1", peers)372 inst2 := newPushPullTestInstance("p2", peers)373 inst3 := newPushPullTestInstance("p3", peers)374 inst4 := newPushPullTestInstance("p4", peers)375 inst5 := newPushPullTestInstance("p5", peers)376 defer inst1.stop()377 defer inst2.stop()378 defer inst3.stop()379 defer inst4.stop()380 defer inst5.stop()381 chooseCounters := make(map[string]int)382 chooseCounters["p2"] = 0383 chooseCounters["p3"] = 0384 chooseCounters["p4"] = 0385 chooseCounters["p5"] = 0386 lock := &sync.Mutex{}387 addToCounters := func(dest string) func(m interface{}) {388 return func(m interface{}) {389 if _, isReq := m.(*reqMsg); isReq {390 lock.Lock()391 chooseCounters[dest]++392 lock.Unlock()393 }394 }395 }396 inst2.hook(addToCounters("p2"))397 inst3.hook(addToCounters("p3"))398 inst4.hook(addToCounters("p4"))399 inst5.hook(addToCounters("p5"))400 for i := 0; i < 100; i++ {401 item := fmt.Sprintf("%d", i)402 inst2.Add(item)403 inst3.Add(item)404 inst4.Add(item)405 }406 inst1.setNextPeerSelection([]string{"p2", "p3", "p4"})407 time.Sleep(time.Duration(2000) * time.Millisecond)408 lock.Lock()409 for pI, counter := range chooseCounters {410 if pI == "p5" {411 assert.Equal(t, 0, counter)412 } else {413 assert.True(t, counter > 0, "%s was not selected!", pI)414 }415 }416 lock.Unlock()417}418func Strcmp(a interface{}, b interface{}) bool {419 return a.(string) == b.(string)420}421func keySet(selfPeer string, m map[string]*pullTestInstance) []string {422 peers := make([]string, len(m)-1)423 i := 0424 for pID := range m {425 if pID == selfPeer {426 continue427 }428 peers[i] = pID429 i++430 }431 return peers432}...
gc_test.go
Source:gc_test.go
...18 const digits = 819 factor := 1 - math.Pow(10, -digits+1)20 return x*factor <= y && y*factor <= x21}22func TestMMU(t *testing.T) {23 t.Parallel()24 // MU25 // 1.0 ***** ***** *****26 // 0.5 * * * *27 // 0.0 ***** *****28 // 0 1 2 3 4 529 util := [][]MutatorUtil{{30 {0e9, 1},31 {1e9, 0},32 {2e9, 1},33 {3e9, 0},34 {4e9, 1},35 {5e9, 0},36 }}37 mmuCurve := NewMMUCurve(util)38 for _, test := range []struct {39 window time.Duration40 want float6441 worst []float6442 }{43 {0, 0, []float64{}},44 {time.Millisecond, 0, []float64{0, 0}},45 {time.Second, 0, []float64{0, 0}},46 {2 * time.Second, 0.5, []float64{0.5, 0.5}},47 {3 * time.Second, 1 / 3.0, []float64{1 / 3.0}},48 {4 * time.Second, 0.5, []float64{0.5}},49 {5 * time.Second, 3 / 5.0, []float64{3 / 5.0}},50 {6 * time.Second, 3 / 5.0, []float64{3 / 5.0}},51 } {52 if got := mmuCurve.MMU(test.window); !aeq(test.want, got) {53 t.Errorf("for %s window, want mu = %f, got %f", test.window, test.want, got)54 }55 worst := mmuCurve.Examples(test.window, 2)56 // Which exact windows are returned is unspecified57 // (and depends on the exact banding), so we just58 // check that we got the right number with the right59 // utilizations.60 if len(worst) != len(test.worst) {61 t.Errorf("for %s window, want worst %v, got %v", test.window, test.worst, worst)62 } else {63 for i := range worst {64 if worst[i].MutatorUtil != test.worst[i] {65 t.Errorf("for %s window, want worst %v, got %v", test.window, test.worst, worst)66 break67 }68 }69 }70 }71}72func TestMMUTrace(t *testing.T) {73 // Can't be t.Parallel() because it modifies the74 // testingOneBand package variable.75 data, err := ioutil.ReadFile("testdata/stress_1_10_good")76 if err != nil {77 t.Fatalf("failed to read input file: %v", err)78 }79 _, events, err := parse(bytes.NewReader(data), "")80 if err != nil {81 t.Fatalf("failed to parse trace: %s", err)82 }83 mu := MutatorUtilization(events.Events, UtilSTW|UtilBackground|UtilAssist)84 mmuCurve := NewMMUCurve(mu)85 // Test the optimized implementation against the "obviously86 // correct" implementation.87 for window := time.Nanosecond; window < 10*time.Second; window *= 10 {88 want := mmuSlow(mu[0], window)89 got := mmuCurve.MMU(window)90 if !aeq(want, got) {91 t.Errorf("want %f, got %f mutator utilization in window %s", want, got, window)92 }93 }94 // Test MUD with band optimization against MUD without band95 // optimization. We don't have a simple testing implementation96 // of MUDs (the simplest implementation is still quite97 // complex), but this is still a pretty good test.98 defer func(old int) { bandsPerSeries = old }(bandsPerSeries)99 bandsPerSeries = 1100 mmuCurve2 := NewMMUCurve(mu)101 quantiles := []float64{0, 1 - .999, 1 - .99}102 for window := time.Microsecond; window < time.Second; window *= 10 {103 mud1 := mmuCurve.MUD(window, quantiles)104 mud2 := mmuCurve2.MUD(window, quantiles)105 for i := range mud1 {106 if !aeq(mud1[i], mud2[i]) {107 t.Errorf("for quantiles %v at window %v, want %v, got %v", quantiles, window, mud2, mud1)108 break...
metrics.go
Source:metrics.go
...7 "github.com/hyperledger/fabric/common/metrics"8 "github.com/hyperledger/fabric/common/metrics/metricsfakes"9 gmetrics "github.com/hyperledger/fabric/gossip/metrics"10)11type TestMetricProvider struct {12 FakeProvider *metricsfakes.Provider13 FakeHeightGauge *metricsfakes.Gauge14 FakeCommitDurationHist *metricsfakes.Histogram15 FakePayloadBufferSizeGauge *metricsfakes.Gauge16 FakeDeclarationGauge *metricsfakes.Gauge17 FakeSentMessages *metricsfakes.Counter18 FakeBufferOverflow *metricsfakes.Counter19 FakeReceivedMessages *metricsfakes.Counter20 FakeTotalGauge *metricsfakes.Gauge21 FakeValidationDuration *metricsfakes.Histogram22 FakeListMissingPrivateDataDuration *metricsfakes.Histogram23 FakeFetchDuration *metricsfakes.Histogram24 FakeCommitPrivateDataDuration *metricsfakes.Histogram25 FakePurgeDuration *metricsfakes.Histogram26 FakeSendDuration *metricsfakes.Histogram27 FakeReconciliationDuration *metricsfakes.Histogram28 FakePullDuration *metricsfakes.Histogram29 FakeRetrieveDuration *metricsfakes.Histogram30}31func TestUtilConstructMetricProvider() *TestMetricProvider {32 fakeProvider := &metricsfakes.Provider{}33 fakeHeightGauge := testUtilConstructGauge()34 fakeCommitDurationHist := testUtilConstructHist()35 fakePayloadBufferSizeGauge := testUtilConstructGauge()36 fakeDeclarationGauge := testUtilConstructGauge()37 fakeSentMessages := testUtilConstructCounter()38 fakeBufferOverflow := testUtilConstructCounter()39 fakeReceivedMessages := testUtilConstructCounter()40 fakeTotalGauge := testUtilConstructGauge()41 fakeValidationDuration := testUtilConstructHist()42 fakeListMissingPrivateDataDuration := testUtilConstructHist()43 fakeFetchDuration := testUtilConstructHist()44 fakeCommitPrivateDataDuration := testUtilConstructHist()45 fakePurgeDuration := testUtilConstructHist()46 fakeSendDuration := testUtilConstructHist()47 fakeReconciliationDuration := testUtilConstructHist()48 fakePullDuration := testUtilConstructHist()49 fakeRetrieveDuration := testUtilConstructHist()50 fakeProvider.NewCounterStub = func(opts metrics.CounterOpts) metrics.Counter {51 switch opts.Name {52 case gmetrics.BufferOverflowOpts.Name:53 return fakeBufferOverflow54 case gmetrics.SentMessagesOpts.Name:55 return fakeSentMessages56 case gmetrics.ReceivedMessagesOpts.Name:57 return fakeReceivedMessages58 }59 return nil60 }61 fakeProvider.NewHistogramStub = func(opts metrics.HistogramOpts) metrics.Histogram {62 switch opts.Name {63 case gmetrics.CommitDurationOpts.Name:64 return fakeCommitDurationHist65 case gmetrics.ValidationDurationOpts.Name:66 return fakeValidationDuration67 case gmetrics.ListMissingPrivateDataDurationOpts.Name:68 return fakeListMissingPrivateDataDuration69 case gmetrics.FetchDurationOpts.Name:70 return fakeFetchDuration71 case gmetrics.CommitPrivateDataDurationOpts.Name:72 return fakeCommitPrivateDataDuration73 case gmetrics.PurgeDurationOpts.Name:74 return fakePurgeDuration75 case gmetrics.SendDurationOpts.Name:76 return fakeSendDuration77 case gmetrics.ReconciliationDurationOpts.Name:78 return fakeReconciliationDuration79 case gmetrics.PullDurationOpts.Name:80 return fakePullDuration81 case gmetrics.RetrieveDurationOpts.Name:82 return fakeRetrieveDuration83 }84 return nil85 }86 fakeProvider.NewGaugeStub = func(opts metrics.GaugeOpts) metrics.Gauge {87 switch opts.Name {88 case gmetrics.PayloadBufferSizeOpts.Name:89 return fakePayloadBufferSizeGauge90 case gmetrics.HeightOpts.Name:91 return fakeHeightGauge92 case gmetrics.LeaderDeclerationOpts.Name:93 return fakeDeclarationGauge94 case gmetrics.TotalOpts.Name:95 return fakeTotalGauge96 }97 return nil98 }99 return &TestMetricProvider{100 fakeProvider,101 fakeHeightGauge,102 fakeCommitDurationHist,103 fakePayloadBufferSizeGauge,104 fakeDeclarationGauge,105 fakeSentMessages,106 fakeBufferOverflow,107 fakeReceivedMessages,108 fakeTotalGauge,109 fakeValidationDuration,110 fakeListMissingPrivateDataDuration,111 fakeFetchDuration,112 fakeCommitPrivateDataDuration,113 fakePurgeDuration,...
Test
Using AI Code Generation
1import "util"2func main() {3 util.Test()4}5import "util"6func main() {7 util.Test()8}9import "fmt"10func Test() {11 fmt.Println("Test")12}13import (14func main() {15 file, err := os.Create("test.txt")16 if err != nil {17 fmt.Println("Error creating file")18 os.Exit(1)19 }20 file.WriteString("Hello World!")21 file.Close()22}23main.main()24import (25func main() {26 file, err := os.Create("test.txt")27 if err != nil {28 fmt.Println("Error creating file")29 os.Exit(1)30 }31 file.WriteString("Hello World!")32 file.Close()33}
Test
Using AI Code Generation
1import "fmt"2func Test() {3 fmt.Println("Test method of util class")4}5import "util"6 C:\Go\src\GoLang\util (from $GOROOT)7 C:\Users\kumar\Documents\GoLang\util (from $GOPATH)
Test
Using AI Code Generation
1util.Test();2util.Test();3util.Test();4util.Test();5util.Test();6util.Test();7util.Test();8util.Test();9util.Test();10util.Test();11util.Test();12util.Test();13util.Test();14util.Test();15util.Test();16util.Test();17util.Test();18util.Test();19util.Test();20util.Test();21util.Test();22util.Test();23util.Test();24util.Test();25util.Test();26util.Test();27util.Test();28util.Test();29util.Test();30util.Test();31util.Test();32util.Test();33util.Test();
Test
Using AI Code Generation
1import (2func main() {3 fmt.Println(util.Test())4}5func Test() string {6}7import (8func main() {9 fmt.Println("test")10}11import (12func main() {13 fmt.Println("test")14}15import (16func main() {17 fmt.Println("test")18}19import (20func main() {21 fmt.Println("test")22}23import (24func main() {25 fmt.Println("test")26}27import (28func main() {29 fmt.Println("test")30}31import (32func main() {33 fmt.Println("test")34}35import (36func main() {37 fmt.Println("test")38}
Test
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello, World!")4 util.Test()5}6import (7func main() {8 fmt.Println("Hello, World!")9 util.Test()10}11import (12func main() {13 fmt.Println("Hello, World!")14 u.Test()15}16import (17func main() {18 fmt.Println("Hello, World!")19 u.Test()20}21Your name to display (optional):22Your name to display (optional):
Test
Using AI Code Generation
1import (2func main() {3 fmt.Println(util.Test())4}5import (6func main() {7 fmt.Println(1.Test())8}9import (10func main() {11 fmt.Println(1.Test())12 fmt.Println(1.Sum(10, 20))13}14import (15func main() {16 fmt.Println(1.Test())17 fmt.Println(1.Sum(10, 20))18 fmt.Println(1.Sum(10, 20, 30))19}20import (21func main() {22 fmt.Println(1.Test())23 fmt.Println(1.Sum(10, 20))24 fmt.Println(1.Sum(10, 20, 30))25 fmt.Println(1.Sum(10, 20, 30, 40))26}27import (28func main() {29 fmt.Println(1.Test())30 fmt.Println(1.Sum(10, 20))31 fmt.Println(1.Sum(10, 20, 30))32 fmt.Println(1.Sum(10, 20, 30, 40))
Test
Using AI Code Generation
1import (2func main() {3 util.Test()4 fmt.Println("Hello World!")5}6 /usr/lib/go-1.10/src/github.com/GoLang/GoLang/util (from $GOROOT)7 /home/username/go/src/github.com/GoLang/GoLang/util (from $GOPATH)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!