func (f factory) NewElection(ctx context.Context, resourceID string) (election2.Election, error) {
	return NewElection(), nil
}
NewElection creates a new Election instance.
TODO(pavelkalinnikov): Use resourceID in tests with multiple resources.
package testonly
import (
	"context"
	"sync"
	"github.com/google/trillian/util/election2"
)
var Factory factory
type Election struct {
	isMaster bool
	revision int
	mu       sync.Mutex
	cond     *sync.Cond
}
func NewElection() *Election {
	e := &Election{}
	e.cond = sync.NewCond(&e.mu)
	return e
}
func (e *Election) update(isMaster bool) {
	e.isMaster = isMaster
	e.revision++
	e.cond.Broadcast()
}
func (e *Election) Await(ctx context.Context) error {
	e.mu.Lock()
	defer e.mu.Unlock()
	if !e.isMaster {
		e.update(true)
	}
	return nil
}
func (e *Election) WithMastership(ctx context.Context) (context.Context, error) {
	e.mu.Lock()
	defer e.mu.Unlock()
	if !e.isMaster {
		cctx, cancel := context.WithCancel(ctx)
		cancel()
		return cctx, nil
	}
	cctx, cancel := watchContext(ctx, &e.mu, e.cond)  
	rev := e.revision
	go func() {  
		defer cancel()
		e.mu.Lock()
		defer e.mu.Unlock()
		for e.isMaster && e.revision == rev && ctx.Err() == nil {
			e.cond.Wait()
		}
	}()
	return cctx, nil
}
func (e *Election) Resign(ctx context.Context) error {
	e.mu.Lock()
	defer e.mu.Unlock()
	e.update(false)
	return nil
}
func (e *Election) Close(ctx context.Context) error {
	return e.Resign(ctx)
}
func watchContext(ctx context.Context, l sync.Locker, cond *sync.Cond) (context.Context, context.CancelFunc) {
	cctx, cancel := context.WithCancel(ctx)
	go func() {
		defer cancel()
		<-cctx.Done()
		l.Lock()  
		defer l.Unlock()
		cond.Broadcast()
	}()
	return cctx, cancel
}
type factory struct{}