mirror of
https://github.com/impact-eintr/netstack.git
synced 2025-10-10 15:20:12 +08:00
base package
This commit is contained in:
47
tmutex/tmutex_test.go
Normal file
47
tmutex/tmutex_test.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package tmutex
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestBasicLock(t *testing.T) {
|
||||
var race = 0
|
||||
var m Mutex
|
||||
m.Init()
|
||||
|
||||
m.Lock()
|
||||
|
||||
go func(){
|
||||
m.Lock()
|
||||
race++
|
||||
m.Unlock()
|
||||
}()
|
||||
|
||||
go func(){
|
||||
m.Lock()
|
||||
race++
|
||||
m.Unlock()
|
||||
}()
|
||||
|
||||
runtime.Gosched() // 让渡cpu
|
||||
race++
|
||||
|
||||
m.Unlock()
|
||||
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
func TestShutOut(t *testing.T) {
|
||||
|
||||
a := 1
|
||||
if a < 3 || func() bool {
|
||||
fmt.Println("ShutOut")
|
||||
return false
|
||||
}() {
|
||||
t.Logf("Ok\n")
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user