package main

import (
	"runtime"
	"testing"
)

type node struct {
	Next  *node
	Value int
}

func TestReachableCycleSurvivesGC(t *testing.T) {
	a, b := &node{Value: 1}, &node{Value: 2}
	a.Next = b
	b.Next = a
	runtime.GC()
	if a.Next.Next != a || a.Next.Value != 2 {
		t.Fatal("reachable graph corrupted")
	}
	runtime.KeepAlive(a)
}
