MCPcopy Create free account
hub / github.com/buke/quickjs-go / TestRuntimeOwnerCheckHooksAndStrictThreadAffinity

Function TestRuntimeOwnerCheckHooksAndStrictThreadAffinity

runtime_test.go:1560–1609  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1558}
1559
1560func 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
1611func TestRuntimeOwnerGoroutineCheckOption(t *testing.T) {
1612 oldGIDHook := ownerCheckCurrentGoroutineID

Callers

nothing calls this directly

Calls 9

ensureOwnerAccessMethod · 0.95
CloseMethod · 0.95
NewRuntimeFunction · 0.85
WithStrictOSThreadFunction · 0.85
currentGoroutineIDFunction · 0.85
currentThreadIDFunction · 0.85
StoreMethod · 0.80
LoadMethod · 0.80
EqualMethod · 0.80

Tested by

no test coverage detected