github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/kit/mq/worker/worker_test.go (about)

     1  package worker_test
     2  
     3  import (
     4  	"context"
     5  	"sync/atomic"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/machinefi/w3bstream/pkg/depends/kit/mq/worker"
    10  )
    11  
    12  func TestWorker(t *testing.T) {
    13  	count := int64(0)
    14  
    15  	w := worker.New(func(ctx context.Context) error {
    16  		c := atomic.LoadInt64(&count)
    17  		atomic.StoreInt64(&count, c+1)
    18  		time.Sleep(100 * time.Millisecond)
    19  		return nil
    20  	}, 2)
    21  
    22  	ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
    23  	defer cancel()
    24  
    25  	w.Start(ctx)
    26  	t.Log(count)
    27  }