github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/sync2/runtime2/goid_test.go (about)

     1  package runtime2
     2  
     3  import (
     4  	"fmt"
     5  	"runtime"
     6  	"testing"
     7  
     8  	"github.com/egonelbre/async"
     9  )
    10  
    11  func TestGOID(t *testing.T) {
    12  	r := async.SpawnWithResult(1000, func(id int) error {
    13  		start := GOID()
    14  		for i := 0; i < 100; i++ {
    15  			runtime.Gosched()
    16  			id := GOID()
    17  			idslow := goidslow()
    18  			if start != id || start != idslow {
    19  				return fmt.Errorf("unstable gid %v / %v / %v", start, id, idslow)
    20  			}
    21  		}
    22  		return nil
    23  	})
    24  
    25  	if errs := r.Wait(); errs != nil {
    26  		n := len(errs)
    27  		if n > 10 {
    28  			n = 10
    29  		}
    30  		for _, err := range errs[:n] {
    31  			t.Error(err)
    32  		}
    33  	}
    34  }