github.com/artisanhe/tools@v1.0.1-0.20210607022958-19a8fef2eb04/mq/worker_test.go (about)

     1  package mq
     2  
     3  import (
     4  	"sync/atomic"
     5  	"testing"
     6  )
     7  
     8  func TestWorker(t *testing.T) {
     9  	count := int64(0)
    10  
    11  	process := func() error {
    12  		c := atomic.LoadInt64(&count)
    13  		atomic.StoreInt64(&count, c+1)
    14  		return nil
    15  	}
    16  
    17  	worker := NewWorker(process, 2)
    18  	go worker.Start()
    19  
    20  	for {
    21  		c := atomic.LoadInt64(&count)
    22  		if c > 10 {
    23  			worker.Stop()
    24  			break
    25  		}
    26  	}
    27  }