Source file src/runtime/testdata/testgoroutineleakprofile/goker/etcd6708.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  	"context"
     9  	"os"
    10  	"runtime"
    11  	"runtime/pprof"
    12  	"sync"
    13  )
    14  
    15  func init() {
    16  	register("Etcd6708", Etcd6708)
    17  }
    18  
    19  type EndpointSelectionMode_etcd6708 int
    20  
    21  const (
    22  	EndpointSelectionRandom_etcd6708 EndpointSelectionMode_etcd6708 = iota
    23  	EndpointSelectionPrioritizeLeader_etcd6708
    24  )
    25  
    26  type MembersAPI_etcd6708 interface {
    27  	Leader(ctx context.Context)
    28  }
    29  
    30  type Client_etcd6708 interface {
    31  	Sync(ctx context.Context)
    32  	SetEndpoints()
    33  	httpClient_etcd6708
    34  }
    35  
    36  type httpClient_etcd6708 interface {
    37  	Do(context.Context)
    38  }
    39  
    40  type httpClusterClient_etcd6708 struct {
    41  	sync.RWMutex
    42  	selectionMode EndpointSelectionMode_etcd6708
    43  }
    44  
    45  func (c *httpClusterClient_etcd6708) getLeaderEndpoint() {
    46  	mAPI := NewMembersAPI_etcd6708(c)
    47  	mAPI.Leader(context.Background())
    48  }
    49  
    50  func (c *httpClusterClient_etcd6708) SetEndpoints() {
    51  	switch c.selectionMode {
    52  	case EndpointSelectionRandom_etcd6708:
    53  	case EndpointSelectionPrioritizeLeader_etcd6708:
    54  		c.getLeaderEndpoint()
    55  	}
    56  }
    57  
    58  func (c *httpClusterClient_etcd6708) Do(ctx context.Context) {
    59  	c.RLock()
    60  	c.RUnlock()
    61  }
    62  
    63  func (c *httpClusterClient_etcd6708) Sync(ctx context.Context) {
    64  	c.Lock()
    65  	defer c.Unlock()
    66  
    67  	c.SetEndpoints()
    68  }
    69  
    70  type httpMembersAPI_etcd6708 struct {
    71  	client httpClient_etcd6708
    72  }
    73  
    74  func (m *httpMembersAPI_etcd6708) Leader(ctx context.Context) {
    75  	m.client.Do(ctx)
    76  }
    77  
    78  func NewMembersAPI_etcd6708(c Client_etcd6708) MembersAPI_etcd6708 {
    79  	return &httpMembersAPI_etcd6708{
    80  		client: c,
    81  	}
    82  }
    83  
    84  func Etcd6708() {
    85  	prof := pprof.Lookup("goroutineleak")
    86  	defer func() {
    87  		// Yield several times to allow the child goroutine to run.
    88  		for i := 0; i < yieldCount; i++ {
    89  			runtime.Gosched()
    90  		}
    91  		prof.WriteTo(os.Stdout, 2)
    92  	}()
    93  
    94  	go func() {
    95  		hc := &httpClusterClient_etcd6708{
    96  			selectionMode: EndpointSelectionPrioritizeLeader_etcd6708,
    97  		}
    98  		hc.Sync(context.Background())
    99  	}()
   100  }
   101  

View as plain text