Skip to content

Commit

Permalink
Add test to verify sync.Mutex internal layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy committed May 24, 2016
1 parent c0e5b5b commit efcec19
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion trylock_test.go
@@ -1,6 +1,22 @@
package trylock

import "testing"
import (
"reflect"
"testing"
)

func TestMutexLayout(t *testing.T) {
sf := reflect.TypeOf((*Mutex)(nil)).Elem().FieldByIndex([]int{0, 0})
if sf.Name != "state" {
t.Fatal("sync.Mutex first field should have name state")
}
if sf.Offset != uintptr(0) {
t.Fatal("sync.Mutex state field should have zero offset")
}
if sf.Type != reflect.TypeOf(int32(1)) {
t.Fatal("sync.Mutex state field type should be int32")
}
}

func TestTryLock(t *testing.T) {
var mu Mutex
Expand Down

0 comments on commit efcec19

Please sign in to comment.