github.com/ethersphere/bee/v2@v2.2.0/pkg/util/syncutil/syncutil_test.go (about)

     1  // Copyright 2023 The Swarm Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package syncutil
     6  
     7  import (
     8  	"sync"
     9  	"testing"
    10  	"time"
    11  )
    12  
    13  func TestWaitWithTimeout(t *testing.T) {
    14  	var wg sync.WaitGroup
    15  
    16  	if !WaitWithTimeout(&wg, 10*time.Millisecond) {
    17  		t.Fatal("want timeout; have none")
    18  	}
    19  
    20  	wg.Add(1)
    21  	if WaitWithTimeout(&wg, 10*time.Millisecond) {
    22  		t.Fatal("have timeout; want none")
    23  	}
    24  
    25  	wg.Done()
    26  	if !WaitWithTimeout(&wg, 10*time.Millisecond) {
    27  		t.Fatal("want no timeout; have none")
    28  	}
    29  }