File: encode_pool_test.go

package info (click to toggle)
golang-github-francoispqt-gojay 1.2.13-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 1,456 kB
  • sloc: makefile: 86
file content (32 lines) | stat: -rw-r--r-- 462 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package gojay

import (
	"fmt"
	"log"
	"strconv"
	"testing"
	"time"
)

func TestConcurrencyMarshal(t *testing.T) {
	var f = func(num int, t *testing.T) {
		for {
			b, err := Marshal(num)
			if err != nil {
				log.Fatal(err)
			}

			s := string(b)
			if n, err := strconv.Atoi(s); err != nil || n != num {
				t.Error(fmt.Errorf(
					"caught race: %v %v", s, num,
				))
			}
		}
	}

	for i := 0; i < 100; i++ {
		go f(i, t)
	}
	time.Sleep(2 * time.Second)
}