Skip to content

Commit

Permalink
Format by gofmt/gofumpt (gofumpt -l -w .)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnteee committed Jun 2, 2022
1 parent a876d42 commit 9ed8992
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions worker/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (workerPoolSelf *DefaultWorkerPool) generateWorkerWithMaximum(maximum int)
workerPoolSelf.lock.Lock()
workerPoolSelf.workerCount--
if isBusy {
workerPoolSelf.workerBusy --
workerPoolSelf.workerBusy--
}
workerPoolSelf.lock.Unlock()
}()
Expand All @@ -211,13 +211,13 @@ func (workerPoolSelf *DefaultWorkerPool) generateWorkerWithMaximum(maximum int)
if job != nil {
workerPoolSelf.lock.Lock()
isBusy = true
workerPoolSelf.workerBusy ++
workerPoolSelf.workerBusy++
workerPoolSelf.lock.Unlock()

job()

workerPoolSelf.lock.Lock()
workerPoolSelf.workerBusy --
workerPoolSelf.workerBusy--
isBusy = false
workerPoolSelf.lock.Unlock()
}
Expand Down
36 changes: 18 additions & 18 deletions worker/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestWorkerJamDuration(t *testing.T) {
defaultWorkerPool := NewDefaultWorkerPool(fpgo.NewBufferedChannelQueue[func()](3, 10000, 100), nil).
SetSpawnWorkerDuration(1 * time.Millisecond / 10).
SetWorkerExpiryDuration(5 * time.Millisecond).
SetWorkerJamDuration(3 * time.Millisecond).
SetWorkerJamDuration(3 * time.Millisecond).
SetWorkerSizeMaximum(10).
SetWorkerSizeStandBy(3).
SetWorkerBatchSize(0)
Expand All @@ -109,14 +109,14 @@ func TestWorkerJamDuration(t *testing.T) {

// Test Spawn
assert.Equal(t, 0, defaultWorkerPool.workerCount)
anyOneDone := false
anyOneDone := false
for i := 0; i < 3; i++ {
v := i
err = workerPool.Schedule(func() {
// Nothing to do
time.Sleep(20 * time.Millisecond)
t.Log(v)
anyOneDone = true
anyOneDone = true
})
assert.NoError(t, err)
}
Expand All @@ -127,20 +127,20 @@ func TestWorkerJamDuration(t *testing.T) {
// Though there're blocking jobs, but no newest job goes into the queue
assert.Equal(t, 3, defaultWorkerPool.workerCount)
// There're new jobs going to the queue, and all goroutines are busy
workerPool.Schedule(func(){})
workerPool.Schedule(func(){})
workerPool.Schedule(func(){})
time.Sleep(3 * time.Millisecond)
workerPool.Schedule(func() {})
workerPool.Schedule(func() {})
workerPool.Schedule(func() {})
time.Sleep(3 * time.Millisecond)
// A new expected goroutine is generated
assert.Equal(t, 4, defaultWorkerPool.workerCount)
workerPool.Schedule(func(){})
workerPool.Schedule(func(){})
workerPool.Schedule(func(){})
assert.Equal(t, 4, defaultWorkerPool.workerCount)
workerPool.Schedule(func() {})
workerPool.Schedule(func() {})
workerPool.Schedule(func() {})
time.Sleep(3 * time.Millisecond)
// Only non blocking jobs, thus keep the same amount
assert.Equal(t, 4, defaultWorkerPool.workerCount)
// There's a blocking jobs going to the queue
workerPool.Schedule(func(){
workerPool.Schedule(func() {
time.Sleep(20 * time.Millisecond)
t.Log(3)
anyOneDone = true
Expand All @@ -149,12 +149,12 @@ func TestWorkerJamDuration(t *testing.T) {
// Though there're blocking jobs, but no newest job goes into the queue
assert.Equal(t, 4, defaultWorkerPool.workerCount)
// There're new jobs going to the queue, and all goroutines are busy
workerPool.Schedule(func(){})
workerPool.Schedule(func(){})
workerPool.Schedule(func(){})
workerPool.Schedule(func(){})
assert.Equal(t, false, anyOneDone)
time.Sleep(1 * time.Millisecond)
workerPool.Schedule(func() {})
workerPool.Schedule(func() {})
workerPool.Schedule(func() {})
workerPool.Schedule(func() {})
assert.Equal(t, false, anyOneDone)
time.Sleep(1 * time.Millisecond)
// A new expected goroutine is generated
assert.Equal(t, 5, defaultWorkerPool.workerCount)
}

0 comments on commit 9ed8992

Please sign in to comment.