gojay

high performance JSON encoder/decoder with stream API for Golang
git clone git://git.lair.cx/gojay
Log | Files | Refs | README | LICENSE

encode_pool_test.go (462B)


      1 package gojay
      2 
      3 import (
      4 	"fmt"
      5 	"log"
      6 	"strconv"
      7 	"testing"
      8 	"time"
      9 )
     10 
     11 func TestConcurrencyMarshal(t *testing.T) {
     12 	var f = func(num int, t *testing.T) {
     13 		for {
     14 			b, err := Marshal(num)
     15 			if err != nil {
     16 				log.Fatal(err)
     17 			}
     18 
     19 			s := string(b)
     20 			if n, err := strconv.Atoi(s); err != nil || n != num {
     21 				t.Error(fmt.Errorf(
     22 					"caught race: %v %v", s, num,
     23 				))
     24 			}
     25 		}
     26 	}
     27 
     28 	for i := 0; i < 100; i++ {
     29 		go f(i, t)
     30 	}
     31 	time.Sleep(2 * time.Second)
     32 }