Source file src/runtime/testdata/testgoroutineleakprofile/goker/cockroach25456.go

     1  // Copyright 2025 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a MIT
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"os"
     9  	"runtime"
    10  	"runtime/pprof"
    11  )
    12  
    13  func init() {
    14  	register("Cockroach25456", Cockroach25456)
    15  }
    16  
    17  type Stopper_cockroach25456 struct {
    18  	quiescer chan struct{}
    19  }
    20  
    21  func (s *Stopper_cockroach25456) ShouldQuiesce() <-chan struct{} {
    22  	if s == nil {
    23  		return nil
    24  	}
    25  	return s.quiescer
    26  }
    27  
    28  func NewStopper_cockroach25456() *Stopper_cockroach25456 {
    29  	return &Stopper_cockroach25456{quiescer: make(chan struct{})}
    30  }
    31  
    32  type Store_cockroach25456 struct {
    33  	stopper          *Stopper_cockroach25456
    34  	consistencyQueue *consistencyQueue_cockroach25456
    35  }
    36  
    37  func (s *Store_cockroach25456) Stopper() *Stopper_cockroach25456 {
    38  	return s.stopper
    39  }
    40  
    41  type Replica_cockroach25456 struct {
    42  	store *Store_cockroach25456
    43  }
    44  
    45  func NewReplica_cockroach25456(store *Store_cockroach25456) *Replica_cockroach25456 {
    46  	return &Replica_cockroach25456{store: store}
    47  }
    48  
    49  type consistencyQueue_cockroach25456 struct{}
    50  
    51  func (q *consistencyQueue_cockroach25456) process(repl *Replica_cockroach25456) {
    52  	<-repl.store.Stopper().ShouldQuiesce()
    53  }
    54  
    55  func newConsistencyQueue_cockroach25456() *consistencyQueue_cockroach25456 {
    56  	return &consistencyQueue_cockroach25456{}
    57  }
    58  
    59  type testContext_cockroach25456 struct {
    60  	store *Store_cockroach25456
    61  	repl  *Replica_cockroach25456
    62  }
    63  
    64  func (tc *testContext_cockroach25456) StartWithStoreConfig(stopper *Stopper_cockroach25456) {
    65  	if tc.store == nil {
    66  		tc.store = &Store_cockroach25456{
    67  			consistencyQueue: newConsistencyQueue_cockroach25456(),
    68  		}
    69  	}
    70  	tc.store.stopper = stopper
    71  	tc.repl = NewReplica_cockroach25456(tc.store)
    72  }
    73  
    74  func Cockroach25456() {
    75  	prof := pprof.Lookup("goroutineleak")
    76  	defer func() {
    77  		// Yield several times to allow the child goroutine to run.
    78  		for i := 0; i < yieldCount; i++ {
    79  			runtime.Gosched()
    80  		}
    81  		prof.WriteTo(os.Stdout, 2)
    82  	}()
    83  	go func() { // G1
    84  		stopper := NewStopper_cockroach25456()
    85  		tc := testContext_cockroach25456{}
    86  		tc.StartWithStoreConfig(stopper)
    87  
    88  		for i := 0; i < 2; i++ {
    89  			tc.store.consistencyQueue.process(tc.repl)
    90  		}
    91  	}()
    92  }
    93  

View as plain text