(t *testing.T)
| 1558 | } |
| 1559 | |
| 1560 | func TestRuntimeOwnerCheckHooksAndStrictThreadAffinity(t *testing.T) { |
| 1561 | oldGIDHook := ownerCheckCurrentGoroutineID |
| 1562 | oldThreadHook := ownerCheckCurrentThreadID |
| 1563 | defer func() { |
| 1564 | ownerCheckCurrentGoroutineID = oldGIDHook |
| 1565 | ownerCheckCurrentThreadID = oldThreadHook |
| 1566 | }() |
| 1567 | |
| 1568 | var gid atomic.Uint64 |
| 1569 | var tid atomic.Uint64 |
| 1570 | gid.Store(11) |
| 1571 | tid.Store(101) |
| 1572 | |
| 1573 | ownerCheckCurrentGoroutineID = func() uint64 { return gid.Load() } |
| 1574 | ownerCheckCurrentThreadID = func() uint64 { return tid.Load() } |
| 1575 | |
| 1576 | var nilRuntime *Runtime |
| 1577 | require.False(t, nilRuntime.ensureOwnerAccess()) |
| 1578 | |
| 1579 | rt := NewRuntime(WithStrictOSThread(true)) |
| 1580 | require.NotNil(t, rt) |
| 1581 | defer rt.Close() |
| 1582 | |
| 1583 | require.True(t, rt.ensureOwnerAccess()) |
| 1584 | require.Equal(t, uint64(11), rt.ownerGoroutineID.Load()) |
| 1585 | require.Equal(t, uint64(101), rt.ownerThreadID.Load()) |
| 1586 | require.NotZero(t, currentGoroutineID()) |
| 1587 | require.NotZero(t, currentThreadID()) |
| 1588 | |
| 1589 | gid.Store(0) |
| 1590 | require.False(t, rt.ensureOwnerAccess()) |
| 1591 | gid.Store(11) |
| 1592 | tid.Store(0) |
| 1593 | require.False(t, rt.ensureOwnerAccess()) |
| 1594 | tid.Store(101) |
| 1595 | |
| 1596 | gid.Store(12) |
| 1597 | require.False(t, rt.ensureOwnerAccess()) |
| 1598 | |
| 1599 | gid.Store(11) |
| 1600 | tid.Store(102) |
| 1601 | require.False(t, rt.ensureOwnerAccess()) |
| 1602 | |
| 1603 | tid.Store(101) |
| 1604 | require.True(t, rt.ensureOwnerAccess()) |
| 1605 | |
| 1606 | rtNoCheck := NewRuntime() |
| 1607 | require.True(t, rtNoCheck.ensureOwnerAccess()) |
| 1608 | rtNoCheck.Close() |
| 1609 | } |
| 1610 | |
| 1611 | func TestRuntimeOwnerGoroutineCheckOption(t *testing.T) { |
| 1612 | oldGIDHook := ownerCheckCurrentGoroutineID |
nothing calls this directly
no test coverage detected