Replace the usage of runtime.SetFinalizer with runtime.AddCleanup in
tests.
Updates #70907
Change-Id: I0d91b6af9643bde278215318f6176277373ddd19
Reviewed-on: https://go-review.googlesource.com/c/go/+/649458
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
func TestMakeClonesStrings(t *testing.T) {
s := strings.Clone("abcdefghijklmnopqrstuvwxyz") // N.B. Must be big enough to not be tiny-allocated.
ran := make(chan bool)
- runtime.SetFinalizer(unsafe.StringData(s), func(_ *byte) {
- ran <- true
- })
+ runtime.AddCleanup(unsafe.StringData(s), func(ch chan bool) {
+ ch <- true
+ }, ran)
h := Make(s)
- // Clean up s (hopefully) and run the finalizer.
+ // Clean up s (hopefully) and run the cleanup.
runtime.GC()
select {