MCPcopy
hub / github.com/gofiber/fiber / TestSetParserDecoderConcurrentAccess

Function TestSetParserDecoderConcurrentAccess

binder/mapping_test.go:462–532  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

460}
461
462func TestSetParserDecoderConcurrentAccess(t *testing.T) {
463 t.Parallel()
464
465 t.Cleanup(func() {
466 SetParserDecoder(ParserConfig{
467 IgnoreUnknownKeys: true,
468 ZeroEmpty: true,
469 })
470 })
471
472 type queryUser struct {
473 Name string `query:"name"`
474 }
475
476 data := map[string][]string{
477 "name": {"fiber"},
478 }
479 parserConfig := ParserConfig{
480 IgnoreUnknownKeys: true,
481 ZeroEmpty: true,
482 }
483
484 start := make(chan struct{})
485 const workers = 25
486 errCh := make(chan error, workers*2)
487 var wg sync.WaitGroup
488
489 runWorker := func(fn func() error) {
490 wg.Go(func() {
491 <-start
492
493 defer func() {
494 if r := recover(); r != nil {
495 errCh <- fmt.Errorf("panic: %v", r)
496 }
497 }()
498
499 if err := fn(); err != nil {
500 errCh <- err
501 }
502 })
503 }
504
505 for range workers {
506 runWorker(func() error {
507 SetParserDecoder(parserConfig)
508 return nil
509 })
510
511 runWorker(func() error {
512 var out queryUser
513 if err := parseToStruct("query", &out, data); err != nil {
514 return err
515 }
516
517 if out.Name != "fiber" {
518 return fmt.Errorf("unexpected name %q", out.Name)
519 }

Callers

nothing calls this directly

Calls 3

SetParserDecoderFunction · 0.85
parseToStructFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected