How to use Parallel method of test Package

Best Go-testdeep code snippet using test.Parallel

benchmarks_test.go

Source:benchmarks_test.go Github

copy

Full Screen

...12 for n := 0; n < b.N; n++ {13 _ = validate.Var(&s, "len=1")14 }15}16func BenchmarkFieldSuccessParallel(b *testing.B) {17 validate := New()18 s := "1"19 b.ResetTimer()20 b.RunParallel(func(pb *testing.PB) {21 for pb.Next() {22 _ = validate.Var(&s, "len=1")23 }24 })25}26func BenchmarkFieldFailure(b *testing.B) {27 validate := New()28 s := "12"29 b.ResetTimer()30 for n := 0; n < b.N; n++ {31 _ = validate.Var(&s, "len=1")32 }33}34func BenchmarkFieldFailureParallel(b *testing.B) {35 validate := New()36 s := "12"37 b.ResetTimer()38 b.RunParallel(func(pb *testing.PB) {39 for pb.Next() {40 _ = validate.Var(&s, "len=1")41 }42 })43}44func BenchmarkFieldArrayDiveSuccess(b *testing.B) {45 validate := New()46 m := []string{"val1", "val2", "val3"}47 b.ResetTimer()48 for n := 0; n < b.N; n++ {49 _ = validate.Var(m, "required,dive,required")50 }51}52func BenchmarkFieldArrayDiveSuccessParallel(b *testing.B) {53 validate := New()54 m := []string{"val1", "val2", "val3"}55 b.ResetTimer()56 b.RunParallel(func(pb *testing.PB) {57 for pb.Next() {58 _ = validate.Var(m, "required,dive,required")59 }60 })61}62func BenchmarkFieldArrayDiveFailure(b *testing.B) {63 validate := New()64 m := []string{"val1", "", "val3"}65 b.ResetTimer()66 for n := 0; n < b.N; n++ {67 _ = validate.Var(m, "required,dive,required")68 }69}70func BenchmarkFieldArrayDiveFailureParallel(b *testing.B) {71 validate := New()72 m := []string{"val1", "", "val3"}73 b.ResetTimer()74 b.RunParallel(func(pb *testing.PB) {75 for pb.Next() {76 _ = validate.Var(m, "required,dive,required")77 }78 })79}80func BenchmarkFieldMapDiveSuccess(b *testing.B) {81 validate := New()82 m := map[string]string{"val1": "val1", "val2": "val2", "val3": "val3"}83 b.ResetTimer()84 for n := 0; n < b.N; n++ {85 _ = validate.Var(m, "required,dive,required")86 }87}88func BenchmarkFieldMapDiveSuccessParallel(b *testing.B) {89 validate := New()90 m := map[string]string{"val1": "val1", "val2": "val2", "val3": "val3"}91 b.ResetTimer()92 b.RunParallel(func(pb *testing.PB) {93 for pb.Next() {94 _ = validate.Var(m, "required,dive,required")95 }96 })97}98func BenchmarkFieldMapDiveFailure(b *testing.B) {99 validate := New()100 m := map[string]string{"": "", "val3": "val3"}101 b.ResetTimer()102 for n := 0; n < b.N; n++ {103 _ = validate.Var(m, "required,dive,required")104 }105}106func BenchmarkFieldMapDiveFailureParallel(b *testing.B) {107 validate := New()108 m := map[string]string{"": "", "val3": "val3"}109 b.ResetTimer()110 b.RunParallel(func(pb *testing.PB) {111 for pb.Next() {112 _ = validate.Var(m, "required,dive,required")113 }114 })115}116func BenchmarkFieldMapDiveWithKeysSuccess(b *testing.B) {117 validate := New()118 m := map[string]string{"val1": "val1", "val2": "val2", "val3": "val3"}119 b.ResetTimer()120 for n := 0; n < b.N; n++ {121 _ = validate.Var(m, "required,dive,keys,required,endkeys,required")122 }123}124func BenchmarkFieldMapDiveWithKeysSuccessParallel(b *testing.B) {125 validate := New()126 m := map[string]string{"val1": "val1", "val2": "val2", "val3": "val3"}127 b.ResetTimer()128 b.RunParallel(func(pb *testing.PB) {129 for pb.Next() {130 _ = validate.Var(m, "required,dive,keys,required,endkeys,required")131 }132 })133}134func BenchmarkFieldMapDiveWithKeysFailure(b *testing.B) {135 validate := New()136 m := map[string]string{"": "", "val3": "val3"}137 b.ResetTimer()138 for n := 0; n < b.N; n++ {139 _ = validate.Var(m, "required,dive,keys,required,endkeys,required")140 }141}142func BenchmarkFieldMapDiveWithKeysFailureParallel(b *testing.B) {143 validate := New()144 m := map[string]string{"": "", "val3": "val3"}145 b.ResetTimer()146 b.RunParallel(func(pb *testing.PB) {147 for pb.Next() {148 _ = validate.Var(m, "required,dive,keys,required,endkeys,required")149 }150 })151}152func BenchmarkFieldCustomTypeSuccess(b *testing.B) {153 validate := New()154 validate.RegisterCustomTypeFunc(ValidateValuerType, (*sql.Valuer)(nil), valuer{})155 val := valuer{156 Name: "1",157 }158 b.ResetTimer()159 for n := 0; n < b.N; n++ {160 _ = validate.Var(val, "len=1")161 }162}163func BenchmarkFieldCustomTypeSuccessParallel(b *testing.B) {164 validate := New()165 validate.RegisterCustomTypeFunc(ValidateValuerType, (*sql.Valuer)(nil), valuer{})166 val := valuer{167 Name: "1",168 }169 b.ResetTimer()170 b.RunParallel(func(pb *testing.PB) {171 for pb.Next() {172 _ = validate.Var(val, "len=1")173 }174 })175}176func BenchmarkFieldCustomTypeFailure(b *testing.B) {177 validate := New()178 validate.RegisterCustomTypeFunc(ValidateValuerType, (*sql.Valuer)(nil), valuer{})179 val := valuer{}180 b.ResetTimer()181 for n := 0; n < b.N; n++ {182 _ = validate.Var(val, "len=1")183 }184}185func BenchmarkFieldCustomTypeFailureParallel(b *testing.B) {186 validate := New()187 validate.RegisterCustomTypeFunc(ValidateValuerType, (*sql.Valuer)(nil), valuer{})188 val := valuer{}189 b.ResetTimer()190 b.RunParallel(func(pb *testing.PB) {191 for pb.Next() {192 _ = validate.Var(val, "len=1")193 }194 })195}196func BenchmarkFieldOrTagSuccess(b *testing.B) {197 validate := New()198 s := "rgba(0,0,0,1)"199 b.ResetTimer()200 for n := 0; n < b.N; n++ {201 _ = validate.Var(s, "rgb|rgba")202 }203}204func BenchmarkFieldOrTagSuccessParallel(b *testing.B) {205 validate := New()206 s := "rgba(0,0,0,1)"207 b.ResetTimer()208 b.RunParallel(func(pb *testing.PB) {209 for pb.Next() {210 _ = validate.Var(s, "rgb|rgba")211 }212 })213}214func BenchmarkFieldOrTagFailure(b *testing.B) {215 validate := New()216 s := "#000"217 b.ResetTimer()218 for n := 0; n < b.N; n++ {219 _ = validate.Var(s, "rgb|rgba")220 }221}222func BenchmarkFieldOrTagFailureParallel(b *testing.B) {223 validate := New()224 s := "#000"225 b.ResetTimer()226 b.RunParallel(func(pb *testing.PB) {227 for pb.Next() {228 _ = validate.Var(s, "rgb|rgba")229 }230 })231}232func BenchmarkStructLevelValidationSuccess(b *testing.B) {233 validate := New()234 validate.RegisterStructValidation(StructValidationTestStructSuccess, TestStruct{})235 tst := TestStruct{236 String: "good value",237 }238 b.ResetTimer()239 for n := 0; n < b.N; n++ {240 _ = validate.Struct(tst)241 }242}243func BenchmarkStructLevelValidationSuccessParallel(b *testing.B) {244 validate := New()245 validate.RegisterStructValidation(StructValidationTestStructSuccess, TestStruct{})246 tst := TestStruct{247 String: "good value",248 }249 b.ResetTimer()250 b.RunParallel(func(pb *testing.PB) {251 for pb.Next() {252 _ = validate.Struct(tst)253 }254 })255}256func BenchmarkStructLevelValidationFailure(b *testing.B) {257 validate := New()258 validate.RegisterStructValidation(StructValidationTestStruct, TestStruct{})259 tst := TestStruct{260 String: "good value",261 }262 b.ResetTimer()263 for n := 0; n < b.N; n++ {264 _ = validate.Struct(tst)265 }266}267func BenchmarkStructLevelValidationFailureParallel(b *testing.B) {268 validate := New()269 validate.RegisterStructValidation(StructValidationTestStruct, TestStruct{})270 tst := TestStruct{271 String: "good value",272 }273 b.ResetTimer()274 b.RunParallel(func(pb *testing.PB) {275 for pb.Next() {276 _ = validate.Struct(tst)277 }278 })279}280func BenchmarkStructSimpleCustomTypeSuccess(b *testing.B) {281 validate := New()282 validate.RegisterCustomTypeFunc(ValidateValuerType, (*sql.Valuer)(nil), valuer{})283 val := valuer{284 Name: "1",285 }286 type Foo struct {287 Valuer valuer `validate:"len=1"`288 IntValue int `validate:"min=5,max=10"`289 }290 validFoo := &Foo{Valuer: val, IntValue: 7}291 b.ResetTimer()292 for n := 0; n < b.N; n++ {293 _ = validate.Struct(validFoo)294 }295}296func BenchmarkStructSimpleCustomTypeSuccessParallel(b *testing.B) {297 validate := New()298 validate.RegisterCustomTypeFunc(ValidateValuerType, (*sql.Valuer)(nil), valuer{})299 val := valuer{300 Name: "1",301 }302 type Foo struct {303 Valuer valuer `validate:"len=1"`304 IntValue int `validate:"min=5,max=10"`305 }306 validFoo := &Foo{Valuer: val, IntValue: 7}307 b.ResetTimer()308 b.RunParallel(func(pb *testing.PB) {309 for pb.Next() {310 _ = validate.Struct(validFoo)311 }312 })313}314func BenchmarkStructSimpleCustomTypeFailure(b *testing.B) {315 validate := New()316 validate.RegisterCustomTypeFunc(ValidateValuerType, (*sql.Valuer)(nil), valuer{})317 val := valuer{}318 type Foo struct {319 Valuer valuer `validate:"len=1"`320 IntValue int `validate:"min=5,max=10"`321 }322 validFoo := &Foo{Valuer: val, IntValue: 3}323 b.ResetTimer()324 for n := 0; n < b.N; n++ {325 _ = validate.Struct(validFoo)326 }327}328func BenchmarkStructSimpleCustomTypeFailureParallel(b *testing.B) {329 validate := New()330 validate.RegisterCustomTypeFunc(ValidateValuerType, (*sql.Valuer)(nil), valuer{})331 val := valuer{}332 type Foo struct {333 Valuer valuer `validate:"len=1"`334 IntValue int `validate:"min=5,max=10"`335 }336 validFoo := &Foo{Valuer: val, IntValue: 3}337 b.ResetTimer()338 b.RunParallel(func(pb *testing.PB) {339 for pb.Next() {340 _ = validate.Struct(validate.Struct(validFoo))341 }342 })343}344func BenchmarkStructFilteredSuccess(b *testing.B) {345 validate := New()346 type Test struct {347 Name string `validate:"required"`348 NickName string `validate:"required"`349 }350 test := &Test{351 Name: "Joey Bloggs",352 }353 byts := []byte("Name")354 fn := func(ns []byte) bool {355 return !bytes.HasSuffix(ns, byts)356 }357 b.ResetTimer()358 for n := 0; n < b.N; n++ {359 _ = validate.StructFiltered(test, fn)360 }361}362func BenchmarkStructFilteredSuccessParallel(b *testing.B) {363 validate := New()364 type Test struct {365 Name string `validate:"required"`366 NickName string `validate:"required"`367 }368 test := &Test{369 Name: "Joey Bloggs",370 }371 byts := []byte("Name")372 fn := func(ns []byte) bool {373 return !bytes.HasSuffix(ns, byts)374 }375 b.ResetTimer()376 b.RunParallel(func(pb *testing.PB) {377 for pb.Next() {378 _ = validate.StructFiltered(test, fn)379 }380 })381}382func BenchmarkStructFilteredFailure(b *testing.B) {383 validate := New()384 type Test struct {385 Name string `validate:"required"`386 NickName string `validate:"required"`387 }388 test := &Test{389 Name: "Joey Bloggs",390 }391 byts := []byte("NickName")392 fn := func(ns []byte) bool {393 return !bytes.HasSuffix(ns, byts)394 }395 b.ResetTimer()396 for n := 0; n < b.N; n++ {397 _ = validate.StructFiltered(test, fn)398 }399}400func BenchmarkStructFilteredFailureParallel(b *testing.B) {401 validate := New()402 type Test struct {403 Name string `validate:"required"`404 NickName string `validate:"required"`405 }406 test := &Test{407 Name: "Joey Bloggs",408 }409 byts := []byte("NickName")410 fn := func(ns []byte) bool {411 return !bytes.HasSuffix(ns, byts)412 }413 b.ResetTimer()414 b.RunParallel(func(pb *testing.PB) {415 for pb.Next() {416 _ = validate.StructFiltered(test, fn)417 }418 })419}420func BenchmarkStructPartialSuccess(b *testing.B) {421 validate := New()422 type Test struct {423 Name string `validate:"required"`424 NickName string `validate:"required"`425 }426 test := &Test{427 Name: "Joey Bloggs",428 }429 b.ResetTimer()430 for n := 0; n < b.N; n++ {431 _ = validate.StructPartial(test, "Name")432 }433}434func BenchmarkStructPartialSuccessParallel(b *testing.B) {435 validate := New()436 type Test struct {437 Name string `validate:"required"`438 NickName string `validate:"required"`439 }440 test := &Test{441 Name: "Joey Bloggs",442 }443 b.ResetTimer()444 b.RunParallel(func(pb *testing.PB) {445 for pb.Next() {446 _ = validate.StructPartial(test, "Name")447 }448 })449}450func BenchmarkStructPartialFailure(b *testing.B) {451 validate := New()452 type Test struct {453 Name string `validate:"required"`454 NickName string `validate:"required"`455 }456 test := &Test{457 Name: "Joey Bloggs",458 }459 b.ResetTimer()460 for n := 0; n < b.N; n++ {461 _ = validate.StructPartial(test, "NickName")462 }463}464func BenchmarkStructPartialFailureParallel(b *testing.B) {465 validate := New()466 type Test struct {467 Name string `validate:"required"`468 NickName string `validate:"required"`469 }470 test := &Test{471 Name: "Joey Bloggs",472 }473 b.ResetTimer()474 b.RunParallel(func(pb *testing.PB) {475 for pb.Next() {476 _ = validate.StructPartial(test, "NickName")477 }478 })479}480func BenchmarkStructExceptSuccess(b *testing.B) {481 validate := New()482 type Test struct {483 Name string `validate:"required"`484 NickName string `validate:"required"`485 }486 test := &Test{487 Name: "Joey Bloggs",488 }489 b.ResetTimer()490 for n := 0; n < b.N; n++ {491 _ = validate.StructExcept(test, "Nickname")492 }493}494func BenchmarkStructExceptSuccessParallel(b *testing.B) {495 validate := New()496 type Test struct {497 Name string `validate:"required"`498 NickName string `validate:"required"`499 }500 test := &Test{501 Name: "Joey Bloggs",502 }503 b.ResetTimer()504 b.RunParallel(func(pb *testing.PB) {505 for pb.Next() {506 _ = validate.StructExcept(test, "NickName")507 }508 })509}510func BenchmarkStructExceptFailure(b *testing.B) {511 validate := New()512 type Test struct {513 Name string `validate:"required"`514 NickName string `validate:"required"`515 }516 test := &Test{517 Name: "Joey Bloggs",518 }519 b.ResetTimer()520 for n := 0; n < b.N; n++ {521 _ = validate.StructExcept(test, "Name")522 }523}524func BenchmarkStructExceptFailureParallel(b *testing.B) {525 validate := New()526 type Test struct {527 Name string `validate:"required"`528 NickName string `validate:"required"`529 }530 test := &Test{531 Name: "Joey Bloggs",532 }533 b.ResetTimer()534 b.RunParallel(func(pb *testing.PB) {535 for pb.Next() {536 _ = validate.StructExcept(test, "Name")537 }538 })539}540func BenchmarkStructSimpleCrossFieldSuccess(b *testing.B) {541 validate := New()542 type Test struct {543 Start time.Time544 End time.Time `validate:"gtfield=Start"`545 }546 now := time.Now().UTC()547 then := now.Add(time.Hour * 5)548 test := &Test{549 Start: now,550 End: then,551 }552 b.ResetTimer()553 for n := 0; n < b.N; n++ {554 _ = validate.Struct(test)555 }556}557func BenchmarkStructSimpleCrossFieldSuccessParallel(b *testing.B) {558 validate := New()559 type Test struct {560 Start time.Time561 End time.Time `validate:"gtfield=Start"`562 }563 now := time.Now().UTC()564 then := now.Add(time.Hour * 5)565 test := &Test{566 Start: now,567 End: then,568 }569 b.ResetTimer()570 b.RunParallel(func(pb *testing.PB) {571 for pb.Next() {572 _ = validate.Struct(test)573 }574 })575}576func BenchmarkStructSimpleCrossFieldFailure(b *testing.B) {577 validate := New()578 type Test struct {579 Start time.Time580 End time.Time `validate:"gtfield=Start"`581 }582 now := time.Now().UTC()583 then := now.Add(time.Hour * -5)584 test := &Test{585 Start: now,586 End: then,587 }588 b.ResetTimer()589 for n := 0; n < b.N; n++ {590 _ = validate.Struct(test)591 }592}593func BenchmarkStructSimpleCrossFieldFailureParallel(b *testing.B) {594 validate := New()595 type Test struct {596 Start time.Time597 End time.Time `validate:"gtfield=Start"`598 }599 now := time.Now().UTC()600 then := now.Add(time.Hour * -5)601 test := &Test{602 Start: now,603 End: then,604 }605 b.ResetTimer()606 b.RunParallel(func(pb *testing.PB) {607 for pb.Next() {608 _ = validate.Struct(test)609 }610 })611}612func BenchmarkStructSimpleCrossStructCrossFieldSuccess(b *testing.B) {613 validate := New()614 type Inner struct {615 Start time.Time616 }617 type Outer struct {618 Inner *Inner619 CreatedAt time.Time `validate:"eqcsfield=Inner.Start"`620 }621 now := time.Now().UTC()622 inner := &Inner{623 Start: now,624 }625 outer := &Outer{626 Inner: inner,627 CreatedAt: now,628 }629 b.ResetTimer()630 for n := 0; n < b.N; n++ {631 _ = validate.Struct(outer)632 }633}634func BenchmarkStructSimpleCrossStructCrossFieldSuccessParallel(b *testing.B) {635 validate := New()636 type Inner struct {637 Start time.Time638 }639 type Outer struct {640 Inner *Inner641 CreatedAt time.Time `validate:"eqcsfield=Inner.Start"`642 }643 now := time.Now().UTC()644 inner := &Inner{645 Start: now,646 }647 outer := &Outer{648 Inner: inner,649 CreatedAt: now,650 }651 b.ResetTimer()652 b.RunParallel(func(pb *testing.PB) {653 for pb.Next() {654 _ = validate.Struct(outer)655 }656 })657}658func BenchmarkStructSimpleCrossStructCrossFieldFailure(b *testing.B) {659 validate := New()660 type Inner struct {661 Start time.Time662 }663 type Outer struct {664 Inner *Inner665 CreatedAt time.Time `validate:"eqcsfield=Inner.Start"`666 }667 now := time.Now().UTC()668 then := now.Add(time.Hour * 5)669 inner := &Inner{670 Start: then,671 }672 outer := &Outer{673 Inner: inner,674 CreatedAt: now,675 }676 b.ResetTimer()677 for n := 0; n < b.N; n++ {678 _ = validate.Struct(outer)679 }680}681func BenchmarkStructSimpleCrossStructCrossFieldFailureParallel(b *testing.B) {682 validate := New()683 type Inner struct {684 Start time.Time685 }686 type Outer struct {687 Inner *Inner688 CreatedAt time.Time `validate:"eqcsfield=Inner.Start"`689 }690 now := time.Now().UTC()691 then := now.Add(time.Hour * 5)692 inner := &Inner{693 Start: then,694 }695 outer := &Outer{696 Inner: inner,697 CreatedAt: now,698 }699 b.ResetTimer()700 b.RunParallel(func(pb *testing.PB) {701 for pb.Next() {702 _ = validate.Struct(outer)703 }704 })705}706func BenchmarkStructSimpleSuccess(b *testing.B) {707 validate := New()708 type Foo struct {709 StringValue string `validate:"min=5,max=10"`710 IntValue int `validate:"min=5,max=10"`711 }712 validFoo := &Foo{StringValue: "Foobar", IntValue: 7}713 b.ResetTimer()714 for n := 0; n < b.N; n++ {715 _ = validate.Struct(validFoo)716 }717}718func BenchmarkStructSimpleSuccessParallel(b *testing.B) {719 validate := New()720 type Foo struct {721 StringValue string `validate:"min=5,max=10"`722 IntValue int `validate:"min=5,max=10"`723 }724 validFoo := &Foo{StringValue: "Foobar", IntValue: 7}725 b.ResetTimer()726 b.RunParallel(func(pb *testing.PB) {727 for pb.Next() {728 _ = validate.Struct(validFoo)729 }730 })731}732func BenchmarkStructSimpleFailure(b *testing.B) {733 validate := New()734 type Foo struct {735 StringValue string `validate:"min=5,max=10"`736 IntValue int `validate:"min=5,max=10"`737 }738 invalidFoo := &Foo{StringValue: "Fo", IntValue: 3}739 b.ResetTimer()740 for n := 0; n < b.N; n++ {741 _ = validate.Struct(invalidFoo)742 }743}744func BenchmarkStructSimpleFailureParallel(b *testing.B) {745 validate := New()746 type Foo struct {747 StringValue string `validate:"min=5,max=10"`748 IntValue int `validate:"min=5,max=10"`749 }750 invalidFoo := &Foo{StringValue: "Fo", IntValue: 3}751 b.ResetTimer()752 b.RunParallel(func(pb *testing.PB) {753 for pb.Next() {754 _ = validate.Struct(invalidFoo)755 }756 })757}758func BenchmarkStructComplexSuccess(b *testing.B) {759 validate := New()760 tSuccess := &TestString{761 Required: "Required",762 Len: "length==10",763 Min: "min=1",764 Max: "1234567890",765 MinMax: "12345",766 Lt: "012345678",767 Lte: "0123456789",768 Gt: "01234567890",769 Gte: "0123456789",770 OmitEmpty: "",771 Sub: &SubTest{772 Test: "1",773 },774 SubIgnore: &SubTest{775 Test: "",776 },777 Anonymous: struct {778 A string `validate:"required"`779 }{780 A: "1",781 },782 Iface: &Impl{783 F: "123",784 },785 }786 b.ResetTimer()787 for n := 0; n < b.N; n++ {788 _ = validate.Struct(tSuccess)789 }790}791func BenchmarkStructComplexSuccessParallel(b *testing.B) {792 validate := New()793 tSuccess := &TestString{794 Required: "Required",795 Len: "length==10",796 Min: "min=1",797 Max: "1234567890",798 MinMax: "12345",799 Lt: "012345678",800 Lte: "0123456789",801 Gt: "01234567890",802 Gte: "0123456789",803 OmitEmpty: "",804 Sub: &SubTest{805 Test: "1",806 },807 SubIgnore: &SubTest{808 Test: "",809 },810 Anonymous: struct {811 A string `validate:"required"`812 }{813 A: "1",814 },815 Iface: &Impl{816 F: "123",817 },818 }819 b.ResetTimer()820 b.RunParallel(func(pb *testing.PB) {821 for pb.Next() {822 _ = validate.Struct(tSuccess)823 }824 })825}826func BenchmarkStructComplexFailure(b *testing.B) {827 validate := New()828 tFail := &TestString{829 Required: "",830 Len: "",831 Min: "",832 Max: "12345678901",833 MinMax: "",834 Lt: "0123456789",835 Lte: "01234567890",836 Gt: "1",837 Gte: "1",838 OmitEmpty: "12345678901",839 Sub: &SubTest{840 Test: "",841 },842 Anonymous: struct {843 A string `validate:"required"`844 }{845 A: "",846 },847 Iface: &Impl{848 F: "12",849 },850 }851 b.ResetTimer()852 for n := 0; n < b.N; n++ {853 _ = validate.Struct(tFail)854 }855}856func BenchmarkStructComplexFailureParallel(b *testing.B) {857 validate := New()858 tFail := &TestString{859 Required: "",860 Len: "",861 Min: "",862 Max: "12345678901",863 MinMax: "",864 Lt: "0123456789",865 Lte: "01234567890",866 Gt: "1",867 Gte: "1",868 OmitEmpty: "12345678901",869 Sub: &SubTest{870 Test: "",871 },872 Anonymous: struct {873 A string `validate:"required"`874 }{875 A: "",876 },877 Iface: &Impl{878 F: "12",879 },880 }881 b.ResetTimer()882 b.RunParallel(func(pb *testing.PB) {883 for pb.Next() {884 _ = validate.Struct(tFail)885 }886 })887}888type TestOneof struct {889 Color string `validate:"oneof=red green"`890}891func BenchmarkOneof(b *testing.B) {892 w := &TestOneof{Color: "green"}893 val := New()894 for i := 0; i < b.N; i++ {895 _ = val.Struct(w)896 }897}898func BenchmarkOneofParallel(b *testing.B) {899 w := &TestOneof{Color: "green"}900 val := New()901 b.ResetTimer()902 b.RunParallel(func(pb *testing.PB) {903 for pb.Next() {904 _ = val.Struct(w)905 }906 })907}...

Full Screen

Full Screen

mode_put_test.go

Source:mode_put_test.go Github

copy

Full Screen

...202 1000,203 10000,204 100000,205 } {206 for _, maxParallelUploads := range []int{207 1,208 2,209 4,210 8,211 16,212 32,213 } {214 name := fmt.Sprintf("count %v parallel %v", count, maxParallelUploads)215 b.Run(name, func(b *testing.B) {216 for n := 0; n < b.N; n++ {217 benchmarkPutUpload(b, nil, count, maxParallelUploads)218 }219 })220 }221 }222}223// benchmarkPutUpload runs a benchmark by uploading a specific number224// of chunks with specified max parallel uploads.225func benchmarkPutUpload(b *testing.B, o *Options, count, maxParallelUploads int) {226 b.StopTimer()227 db, cleanupFunc := newTestDB(b, o)228 defer cleanupFunc()229 uploader := db.NewPutter(ModePutUpload)230 chunks := make([]storage.Chunk, count)231 for i := 0; i < count; i++ {232 chunks[i] = generateFakeRandomChunk()233 }234 errs := make(chan error)235 b.StartTimer()236 go func() {237 sem := make(chan struct{}, maxParallelUploads)238 for i := 0; i < count; i++ {239 sem <- struct{}{}240 go func(i int) {241 defer func() { <-sem }()242 errs <- uploader.Put(chunks[i])243 }(i)244 }245 }()246 for i := 0; i < count; i++ {247 err := <-errs248 if err != nil {249 b.Fatal(err)250 }251 }...

Full Screen

Full Screen

t_test.go

Source:t_test.go Github

copy

Full Screen

...7func TestingFunctionLooksLikeATestButIsNotWithParam() {}8func TestingFunctionLooksLikeATestButIsWithParam(i int) {}9func AbcFunctionSuccessful(t *testing.T) {}10func TestFunctionSuccessfulRangeTest(t *testing.T) {11 t.Parallel()12 testCases := []struct {13 name string14 }{{name: "foo"}}15 for _, tc := range testCases {16 tc := tc17 t.Run(tc.name, func(x *testing.T) {18 x.Parallel()19 fmt.Println(tc.name)20 })21 }22}23func TestFunctionSuccessfulNoRangeTest(t *testing.T) {24 t.Parallel()25 testCases := []struct {26 name string27 }{{name: "foo"}, {name: "bar"}}28 t.Run(testCases[0].name, func(t *testing.T) {29 t.Parallel()30 fmt.Println(testCases[0].name)31 })32 t.Run(testCases[1].name, func(t *testing.T) {33 t.Parallel()34 fmt.Println(testCases[1].name)35 })36}37func TestFunctionMissingCallToParallel(t *testing.T) {} // want "Function TestFunctionMissingCallToParallel missing the call to method parallel"38func TestFunctionRangeMissingCallToParallel(t *testing.T) {39 t.Parallel()40 testCases := []struct {41 name string42 }{{name: "foo"}}43 // this range loop should be okay as it does not have test Run44 for _, tc := range testCases {45 fmt.Println(tc.name)46 }47 for _, tc := range testCases { // want "Range statement for test TestFunctionRangeMissingCallToParallel missing the call to method parallel in test Run"48 t.Run(tc.name, func(t *testing.T) {49 fmt.Println(tc.name)50 })51 }52}53func TestFunctionMissingCallToParallelAndRangeNotUsingRangeValueInTDotRun(t *testing.T) { // want "Function TestFunctionMissingCallToParallelAndRangeNotUsingRangeValueInTDotRun missing the call to method parallel"54 testCases := []struct {55 name string56 }{{name: "foo"}}57 for _, tc := range testCases { // want "Range statement for test TestFunctionMissingCallToParallelAndRangeNotUsingRangeValueInTDotRun missing the call to method parallel in test Run"58 t.Run(tc.name, func(t *testing.T) {59 fmt.Println(tc.name)60 })61 }62}63func TestFunctionRangeNotUsingRangeValueInTDotRun(t *testing.T) {64 t.Parallel()65 testCases := []struct {66 name string67 }{{name: "foo"}}68 for _, tc := range testCases { // want "Range statement for test TestFunctionRangeNotUsingRangeValueInTDotRun does not reinitialise the variable tc"69 t.Run("tc.name", func(t *testing.T) {70 t.Parallel()71 fmt.Println(tc.name)72 })73 }74}75func TestFunctionRangeNotReInitialisingVariable(t *testing.T) {76 t.Parallel()77 testCases := []struct {78 name string79 }{{name: "foo"}}80 for _, tc := range testCases { // want "Range statement for test TestFunctionRangeNotReInitialisingVariable does not reinitialise the variable tc"81 t.Run(tc.name, func(t *testing.T) {82 t.Parallel()83 fmt.Println(tc.name)84 })85 }86}87func TestFunctionTwoTestRunMissingCallToParallel(t *testing.T) {88 t.Parallel()89 t.Run("1", func(t *testing.T) { // want "Function TestFunctionTwoTestRunMissingCallToParallel has missing the call to method parallel in the test run"90 fmt.Println("1")91 })92 t.Run("2", func(t *testing.T) { // want "Function TestFunctionTwoTestRunMissingCallToParallel has missing the call to method parallel in the test run"93 fmt.Println("2")94 })95}96func TestFunctionFirstOneTestRunMissingCallToParallel(t *testing.T) {97 t.Parallel()98 t.Run("1", func(t *testing.T) { // want "Function TestFunctionFirstOneTestRunMissingCallToParallel has missing the call to method parallel in the test run"99 fmt.Println("1")100 })101 t.Run("2", func(t *testing.T) {102 t.Parallel()103 fmt.Println("2")104 })105}106func TestFunctionSecondOneTestRunMissingCallToParallel(t *testing.T) {107 t.Parallel()108 t.Run("1", func(x *testing.T) {109 x.Parallel()110 fmt.Println("1")111 })112 t.Run("2", func(t *testing.T) { // want "Function TestFunctionSecondOneTestRunMissingCallToParallel has missing the call to method parallel in the test run"113 fmt.Println("2")114 })115}116type notATest int117func (notATest) Run(args ...interface{}) {}118func (notATest) Parallel() {}119func TestFunctionWithRunLookalike(t *testing.T) {120 t.Parallel()121 var other notATest122 // These aren't t.Run, so they shouldn't be flagged as Run invocations missing calls to Parallel.123 other.Run(1, 1)124 other.Run(2, 2)125}126func TestFunctionWithParallelLookalike(t *testing.T) { // want "Function TestFunctionWithParallelLookalike missing the call to method parallel"127 var other notATest128 // This isn't t.Parallel, so it doesn't qualify as a call to Parallel.129 other.Parallel()130}131func TestFunctionWithOtherTestingVar(q *testing.T) {132 q.Parallel()133}...

Full Screen

Full Screen

Parallel

Using AI Code Generation

copy

Full Screen

1func TestParallel(t *testing.T) {2 t.Parallel()3 time.Sleep(2 * time.Second)4 fmt.Println("test 1")5}6func TestParallel2(t *testing.T) {7 t.Parallel()8 time.Sleep(2 * time.Second)9 fmt.Println("test 2")10}11func TestParallel3(t *testing.T) {12 t.Parallel()13 time.Sleep(2 * time.Second)14 fmt.Println("test 3")15}16func TestParallel4(t *testing.T) {17 t.Parallel()18 time.Sleep(2 * time.Second)19 fmt.Println("test 4")20}21func TestParallel5(t *testing.T) {22 t.Parallel()23 time.Sleep(2 * time.Second)24 fmt.Println("test 5")25}26func TestParallel6(t *testing.T) {27 t.Parallel()28 time.Sleep(2 * time.Second)29 fmt.Println("test 6")30}31func TestParallel7(t *testing.T) {32 t.Parallel()33 time.Sleep(2 * time.Second)34 fmt.Println("test 7")35}36func TestParallel8(t *testing.T) {37 t.Parallel()38 time.Sleep(2 * time.Second)39 fmt.Println("test 8")40}41func TestParallel9(t *testing.T) {42 t.Parallel()43 time.Sleep(2 * time.Second)44 fmt.Println("test 9")45}46func TestParallel10(t *testing.T) {47 t.Parallel()48 time.Sleep(2 * time.Second)49 fmt.Println("test 10")50}51func TestRun(t *testing.T) {52 t.Run("test1", func(t *testing.T) {53 time.Sleep(2 * time.Second)54 fmt.Println("test 1")55 })56 t.Run("test2", func(t *testing.T) {57 time.Sleep(2 * time.Second)58 fmt.Println("test 2")59 })60 t.Run("test3", func(t *testing.T) {61 time.Sleep(2 * time.Second)62 fmt.Println("test 3")63 })64 t.Run("test4", func(t *testing.T) {65 time.Sleep(2 * time.Second)66 fmt.Println("test 4")67 })68 t.Run("test5", func(t *testing

Full Screen

Full Screen

Parallel

Using AI Code Generation

copy

Full Screen

1import (2func TestParallel(t *testing.T) {3 t.Parallel()4}5import (6func TestSubtest(t *testing.T) {7 t.Run("subtest", func(t *testing.T) {8 })9}10import (11func TestRun(t *testing.T) {12 t.Run("subtest", func(t *testing.T) {13 t.Run("subtest", func(t *testing.T) {14 })15 })16}17import (18func TestRun(t *testing.T) {19 t.Run("sub

Full Screen

Full Screen

Parallel

Using AI Code Generation

copy

Full Screen

1func TestParallel(t *testing.T) {2 t.Parallel()3 time.Sleep(2 * time.Second)4 fmt.Println("TestParallel")5}6func TestParallel1(t *testing.T) {7 t.Parallel()8 time.Sleep(2 * time.Second)9 fmt.Println("TestParallel1")10}11func TestParallel2(t *testing.T) {12 t.Parallel()13 time.Sleep(2 * time.Second)14 fmt.Println("TestParallel2")15}16func TestParallel3(t *testing.T) {17 t.Parallel()18 time.Sleep(2 * time.Second)19 fmt.Println("TestParallel3")20}21func TestParallel4(t *testing.T) {22 t.Parallel()23 time.Sleep(2 * time.Second)24 fmt.Println("TestParallel4")25}26func TestParallel5(t *testing.T) {27 t.Parallel()28 time.Sleep(2 * time.Second)29 fmt.Println("TestParallel5")30}31func TestParallel6(t *testing.T) {32 t.Parallel()33 time.Sleep(2 * time.Second)34 fmt.Println("TestParallel6")35}36func TestParallel7(t *testing.T) {37 t.Parallel()38 time.Sleep(2 * time.Second)39 fmt.Println("TestParallel7")40}41func TestParallel8(t *testing.T) {42 t.Parallel()43 time.Sleep(2 * time.Second)44 fmt.Println("TestParallel8")45}46func TestParallel9(t *testing.T) {47 t.Parallel()48 time.Sleep(2 * time.Second)49 fmt.Println("TestParallel9")50}51func TestParallel10(t *testing.T) {52 t.Parallel()53 time.Sleep(2 * time.Second)54 fmt.Println("TestParallel10")55}56func TestParallel11(t *testing.T) {57 t.Parallel()58 time.Sleep(2 * time.Second)59 fmt.Println("TestParallel11")60}61func TestParallel12(t *testing.T) {62 t.Parallel()63 time.Sleep(2 * time.Second)64 fmt.Println("TestParallel12")65}66func TestParallel13(t *testing.T) {67 t.Parallel()68 time.Sleep(2 * time.Second)69 fmt.Println("TestParallel13")70}71func TestParallel14(t *testing.T) {72 t.Parallel()73 time.Sleep(2 * time.Second)74 fmt.Println("TestParallel14")75}76func TestParallel15(t

Full Screen

Full Screen

Parallel

Using AI Code Generation

copy

Full Screen

1func TestParallel(t *testing.T) {2 t.Parallel()3 time.Sleep(2 * time.Second)4 fmt.Println("test parallel")5}6func TestRun(t *testing.T) {7 t.Run("subtest1", func(t *testing.T) {8 time.Sleep(2 * time.Second)9 fmt.Println("test run")10 })11}12func TestRunParallel(t *testing.T) {13 t.RunParallel(func(pb *testing.PB) {14 for pb.Next() {15 time.Sleep(2 * time.Second)16 fmt.Println("test run parallel")17 }18 })19}20--- PASS: TestParallel (2.00s)21--- PASS: TestRun (2.00s)22--- PASS: TestRunParallel (2.00s)23GoLang: How to use t.Helper() method of testing package24GoLang: How to use t.Fatal() and t.Fatalf() methods of testing package25GoLang: How to use t.Log() and t.Logf() methods of testing package26GoLang: How to use t.Skip() and t.Skipf() methods of testing package27GoLang: How to use t.Parallel() method of testing package28GoLang: How to use t.Run() method of testing package29GoLang: How to use t.RunParallel() method of testing package30GoLang: How to use t.Error() and t.Errorf() methods of testing package31GoLang: How to use t.Fail() and t.FailNow() methods of testing package32GoLang: How to use t.Cleanup() method of testing package33GoLang: How to use t.TempDir() and t.TempDir() methods of testing package34GoLang: How to use t.Helper() method of testing package35GoLang: How to use t.Helper() method of testing package

Full Screen

Full Screen

Parallel

Using AI Code Generation

copy

Full Screen

1import (2func TestParallel(t *testing.T) {3 t.Parallel()4 fmt.Println("This is parallel test")5}6func TestNotParallel(t *testing.T) {7 fmt.Println("This is not parallel test")8}9--- PASS: TestNotParallel (0.00s)10--- PASS: TestParallel (0.00s)

Full Screen

Full Screen

Parallel

Using AI Code Generation

copy

Full Screen

1import (2func TestParallel(t *testing.T) {3 t.Parallel()4 time.Sleep(2 * time.Second)5 fmt.Println("TestParallel")6}7func TestParallel2(t *testing.T) {8 t.Parallel()9 time.Sleep(2 * time.Second)10 fmt.Println("TestParallel2")11}12func TestParallel3(t *testing.T) {13 t.Parallel()14 time.Sleep(2 * time.Second)15 fmt.Println("TestParallel3")16}17func TestParallel4(t *testing.T) {18 t.Parallel()19 time.Sleep(2 * time.Second)20 fmt.Println("TestParallel4")21}22func TestParallel5(t *testing.T) {23 t.Parallel()24 time.Sleep(2 * time.Second)25 fmt.Println("TestParallel5")26}27func TestParallel6(t *testing.T) {28 t.Parallel()29 time.Sleep(2 * time.Second)30 fmt.Println("TestParallel6")31}32func TestParallel7(t *testing.T) {33 t.Parallel()34 time.Sleep(2 * time.Second)35 fmt.Println("TestParallel7")36}37func TestParallel8(t *testing.T) {38 t.Parallel()39 time.Sleep(2 * time.Second)40 fmt.Println("TestParallel8")41}42func TestParallel9(t *testing.T) {43 t.Parallel()44 time.Sleep(2 * time.Second)45 fmt.Println("TestParallel9")46}47func TestParallel10(t *testing.T) {48 t.Parallel()49 time.Sleep(2 * time.Second)50 fmt.Println("TestParallel10")51}52func TestParallel11(t *testing.T) {53 t.Parallel()54 time.Sleep(2 * time.Second)55 fmt.Println("TestParallel11")56}57func TestParallel12(t *testing.T) {58 t.Parallel()59 time.Sleep(2 * time.Second)60 fmt.Println("TestParallel12")61}62--- PASS: TestParallel (2.00s)63--- PASS: TestParallel2 (2.00s)

Full Screen

Full Screen

Parallel

Using AI Code Generation

copy

Full Screen

1import (2func TestParallel(t *testing.T) {3 fmt.Println("Parallel")4}5func TestParallel2(t *testing.T) {6 fmt.Println("Parallel2")7}8func TestParallel3(t *testing.T) {9 fmt.Println("Parallel3")10}11func TestParallel4(t *testing.T) {12 fmt.Println("Parallel4")13}14func TestParallel5(t *testing.T) {15 fmt.Println("Parallel5")16}17func TestParallel6(t *testing.T) {18 fmt.Println("Parallel6")19}20func TestParallel7(t *testing.T) {21 fmt.Println("Parallel7")22}23func TestParallel8(t *testing.T) {24 fmt.Println("Parallel8")25}26func TestParallel9(t *testing.T) {27 fmt.Println("Parallel9")28}29func TestParallel10(t *testing.T) {30 fmt.Println("Parallel10")31}32func TestParallel11(t *testing.T) {33 fmt.Println("Parallel11")34}35func TestParallel12(t *testing.T) {36 fmt.Println("Parallel12")37}38func TestParallel13(t *testing.T) {39 fmt.Println("Parallel13")40}41func TestParallel14(t *testing.T) {42 fmt.Println("Parallel14")43}44func TestParallel15(t *testing.T) {45 fmt.Println("Parallel15")46}47func TestParallel16(t *testing.T) {48 fmt.Println("Parallel16")49}50func TestParallel17(t *testing.T) {51 fmt.Println("Parallel17")52}53func TestParallel18(t *testing.T) {54 fmt.Println("Parallel18")55}56func TestParallel19(t *testing.T) {57 fmt.Println("Parallel19")58}59func TestParallel20(t *testing.T) {60 fmt.Println("Parallel20")61}62func TestParallel21(t *testing.T) {63 fmt.Println("Parallel21")64}65func TestParallel22(t *testing.T) {66 fmt.Println("Parallel22")67}68func TestParallel23(t *testing.T) {69 fmt.Println("Parallel23")70}71func TestParallel24(t *testing.T) {72 fmt.Println("Parallel24")73}74func TestParallel25(t *testing.T) {75 fmt.Println("Parallel25")76}77func TestParallel26(t *testing.T) {78 fmt.Println("Parallel26")79}80func TestParallel27(t *testing.T) {81 fmt.Println("Parallel27")82}

Full Screen

Full Screen

Parallel

Using AI Code Generation

copy

Full Screen

1import (2func TestParallel(t *testing.T) {3 t.Parallel()4 time.Sleep(2 * time.Second)5 fmt.Println("test parallel")6}7func TestNonParallel(t *testing.T) {8 time.Sleep(2 * time.Second)9 fmt.Println("test non parallel")10}11--- PASS: TestNonParallel (2.00s)12--- PASS: TestParallel (2.00s)

Full Screen

Full Screen

Parallel

Using AI Code Generation

copy

Full Screen

1import (2func TestParallel(t *testing.T) {3 t.Parallel()4}5import (6func TestRun(t *testing.T) {7}8import (9func TestRun(t *testing.T) {10}11import (12func TestParallel(t *testing.T) {13 t.Parallel()14}15import (16func TestRun(t *testing.T) {17}18import (19func TestRun(t *testing.T) {20}21import (22func TestParallel(t *testing.T) {23 t.Parallel()24}25import (26func TestRun(t *testing.T) {27}28import (29func TestRun(t *testing.T) {30}31import (32func TestParallel(t *testing.T) {33 t.Parallel()34}35import (36func TestRun(t *testing.T) {37}38import (

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful