ronantakizawa/codereview-bench huggingface dataset:
Repository: etcd-io/etcd
File: cache/demux.go (Go)

Code before:
func (d *demux) Compact(compactRev int64) {
	d.mu.Lock()
	defer d.mu.Unlock()
	d.purge()
}

func (d *demux) resyncLaggingWatchers() {
	d.mu.Lock()
	defer d.mu.Unlock()

	if d.minRev == 0 {
		return
	}

	for w, nextRev := range d.laggingWatchers {
		if nextRev < d.minRev {
			w.Compact(nextRev)
			delete(d.laggingWatchers, w)
			continue
		}
		// TODO: re-enable key‐predicate in Filter when non‐zero startRev or performance tuning is needed
		enqueueFailed := false
		d.history.AscendGreaterOrEqual(nextRev, func(rev int64, eventBatch []*clientv3.Event) bool {
			if !w.enqueueResponse(clientv3.WatchResponse{
				Events: eventBatch,
			}) { // buffer overflow: watcher still lagging
				enqueueFailed = true
				return false
			}
			nextRev = rev + 1
			return true
		})
		// Send progress to just resync.
		if !enqueueFailed && d.maxRev > nextRev {
			if w.enqueueResponse(clientv3.WatchResponse{
				Header: etcdserverpb.ResponseHeader{Revision: d.maxRev},
			}) {
				nextRev = d.maxRev + 1
			}
		}

		if !enqueueFailed {
			delete(d.laggingWatchers, w)
			d.activeWatchers[w] = nextRev
		} else {
			d.laggingWatchers[w] = nextRev
		}
	}
}


Review comment (bug):
```suggestion
			resp := clientv3.WatchResponse{
				Events: eventBatch,
			}
			if !w.enqueueResponse(resp) { // buffer overflow: watcher still lagging
```

Code after:
		w.Stop()
	}
	d.activeWatchers = make(map[*watcher]int64)
	d.laggingWatchers = make(map[*watcher]int64)
}

// Compact is called when etcd reports a compaction at compactRev to rebase history;
// it keeps provably-too-old watchers for later cancellation, stops others, and clients should resubscribe.
func (d *demux) Compact(compactRev int64) {
	d.mu.Lock()
	defer d.mu.Unlock()
	d.purge()
}

func (d *demux) resyncLaggingWatchers() {
	d.mu.Lock()
	defer d.mu.Unlock()

	if d.minRev == 0 {
		return
	}

	for w, nextRev := range d.laggingWatchers {
		if nextRev < d.minRev {
			w.Compact(nextRev)
			delete(d.laggingWatchers, w)
			continue
		}
		// TODO: re-enable key‐predicate in Filter when non‐zero startRev or performance tuning is needed
		resyncSuccess := true
		d.history.AscendGreaterOrEqual(nextRev, func(rev int64, eventBatch []*clientv3.Event) bool {
			resp := clientv3.WatchResponse{
				Events: eventBatch,
			}
			if !w.enqueueResponse(resp) { // buffer overflow: watcher still lagging
				resyncSuccess = false
				return false
			}
			nextRev = rev + 1
			return true
		})
		// Send progress to just resync.
		if resyncSuccess {
			resp := clientv3.WatchResponse{
				Header: etcdserverpb.ResponseHeader{Revision: d.maxRev},
			}
			if d.maxRev > nextRev && w.enqueueResponse(resp) {
				nextRev = d.maxRev + 1
			}
			delete(d.laggingWatchers, w)
			d.activeWatchers[w] = nextRev
Repository: etcd-io/etcd
File: cache/demux.go (Go)

Code before:
			w.Compact(nextRev)
			delete(d.laggingWatchers, w)
			continue
		}
		// TODO: re-enable key‐predicate in Filter when non‐zero startRev or performance tuning is needed
		enqueueFailed := false
		d.history.AscendGreaterOrEqual(nextRev, func(rev int64, eventBatch []*clientv3.Event) bool {
			if !w.enqueueResponse(clientv3.WatchResponse{
				Events: eventBatch,
			}) { // buffer overflow: watcher still lagging
				enqueueFailed = true
				return false
			}
			nextRev = rev + 1
			return true
		})
		// Send progress to just resync.
		if !enqueueFailed && d.maxRev > nextRev {
			if w.enqueueResponse(clientv3.WatchResponse{
				Header: etcdserverpb.ResponseHeader{Revision: d.maxRev},
			}) {
				nextRev = d.maxRev + 1
			}
		}

		if !enqueueFailed {
			delete(d.laggingWatchers, w)
			d.activeWatchers[w] = nextRev
		} else {
			d.laggingWatchers[w] = nextRev
		}
	}
}


Review comment (suggestion):
```suggestion
		if resyncSucccess {
			resp := clientv3.WatchResponse{
				Header: etcdserverpb.ResponseHeader{Revision: d.maxRev},
			}
			if d.maxRev > nextRev && w.enqueueResponse(c) {
				nextRev = d.maxRev + 1
			}
			delete(d.laggingWatchers, w)
			d.activeWatchers[w] = nextRev
		} else {
			d.laggingWatchers[w] = nextRev
		}
```

Code after:
	defer d.mu.Unlock()

	if d.minRev == 0 {
		return
	}

	for w, nextRev := range d.laggingWatchers {
		if nextRev < d.minRev {
			w.Compact(nextRev)
			delete(d.laggingWatchers, w)
			continue
		}
		// TODO: re-enable key‐predicate in Filter when non‐zero startRev or performance tuning is needed
		resyncSuccess := true
		d.history.AscendGreaterOrEqual(nextRev, func(rev int64, eventBatch []*clientv3.Event) bool {
			resp := clientv3.WatchResponse{
				Events: eventBatch,
			}
			if !w.enqueueResponse(resp) { // buffer overflow: watcher still lagging
				resyncSuccess = false
				return false
			}
			nextRev = rev + 1
			return true
		})
		// Send progress to just resync.
		if resyncSuccess {
			resp := clientv3.WatchResponse{
				Header: etcdserverpb.ResponseHeader{Revision: d.maxRev},
			}
			if d.maxRev > nextRev && w.enqueueResponse(resp) {
				nextRev = d.maxRev + 1
			}
			delete(d.laggingWatchers, w)
			d.activeWatchers[w] = nextRev
		} else {
			d.laggingWatchers[w] = nextRev
		}
	}
}
Repository: etcd-io/etcd
File: cache/demux.go (Go)

Code before:
			if ev.Kv.ModRevision >= nextRev {
				sendStart = i
				break
			}
		}
		if sendStart == len(events) {
			continue
		}

		if !w.enqueueEvent(events[sendStart:]) { // overflow → lagging
			d.laggingWatchers[w] = nextRev
			delete(d.activeWatchers, w)
		} else {
			d.activeWatchers[w] = lastRev + 1
		}
	}
}

// Purge stops all watchers and rebase history on watch errors
func (d *demux) Purge() {
	d.mu.Lock()
	defer d.mu.Unlock()
	d.purge()
}

func (d *demux) purge() {
	d.maxRev = 0
	d.minRev = 0
	d.history.RebaseHistory()
	for w := range d.activeWatchers {
		w.Stop()
	}
	for w := range d.laggingWatchers {
		w.Stop()
	}
	d.activeWatchers = make(map[*watcher]int64)
	d.laggingWatchers = make(map[*watcher]int64)
}

// Compact is called when etcd reports a compaction at compactRev to rebase history;
// it keeps provably-too-old watchers for later cancellation, stops others, and clients should resubscribe.
func (d *demux) Compact(compactRev int64) {
	d.mu.Lock()
	defer d.mu.Unlock()
	d.purge()
}

func (d *demux) resyncLaggingWatchers() {
	d.mu.Lock()
	defer d.mu.Unlock()


Review comment (suggestion):
Note: A periodic progress notify should only be send to watchers that enabled it when creating watch. We can implement that in a followup.

Code after:
		d.history.Append(events[batchStart:])
	}
	d.maxRev = events[len(events)-1].Kv.ModRevision
}

func (d *demux) broadcastLocked(resp clientv3.WatchResponse) {
	switch {
	case resp.IsProgressNotify():
		d.broadcastProgressLocked(resp.Header.Revision)
	case len(resp.Events) != 0:
		d.broadcastEventsLocked(resp.Events)
	default:
	}
}

func (d *demux) broadcastProgressLocked(progressRev int64) {
	for w, nextRev := range d.activeWatchers {
		if nextRev >= progressRev {
			continue
		}
		resp := clientv3.WatchResponse{
			Header: etcdserverpb.ResponseHeader{
				Revision: progressRev,
			},
		}
		if w.enqueueResponse(resp) {
			d.activeWatchers[w] = progressRev + 1
		}
	}
}

func (d *demux) broadcastEventsLocked(events []*clientv3.Event) {
	firstRev := events[0].Kv.ModRevision
	lastRev := events[len(events)-1].Kv.ModRevision

	for w, nextRev := range d.activeWatchers {
		if nextRev != 0 && firstRev > nextRev {
			d.laggingWatchers[w] = nextRev
			delete(d.activeWatchers, w)
			continue
		}

		sendStart := len(events)
		for i, ev := range events {
			if ev.Kv.ModRevision >= nextRev {
				sendStart = i
				break
			}
		}

		if sendStart == len(events) {
Repository: etcd-io/etcd
File: cache/demux.go (Go)

Code before:
		d.activeWatchers[w] = startingRev
	}
}

func (d *demux) Unregister(w *watcher) {
	func() {
		d.mu.Lock()
		defer d.mu.Unlock()
		delete(d.activeWatchers, w)
		delete(d.laggingWatchers, w)
	}()
	w.Stop()
}

func (d *demux) Init(minRev int64) {
	d.mu.Lock()
	defer d.mu.Unlock()
	if d.minRev == 0 {
		// Watch started for empty demux
		d.minRev = minRev
		return
	}
	if d.maxRev == 0 {
		// Watch started on initialized demux that never got any event.
		d.purge()
	}
	if minRev == d.maxRev+1 {
		// Watch continuing from last revision it observed.
		return
	}
	// Watch opened on revision mismatching dmux last observed revision.
	d.purge()
	d.minRev = minRev
}

func (d *demux) Broadcast(resp clientv3.WatchResponse) error {
	events := resp.Events
	if len(events) == 0 {
		return nil
	}

	d.mu.Lock()
	defer d.mu.Unlock()
	err := validateRevisions(events, d.maxRev)
	if err != nil {
		return err
	}
	d.updateStoreLocked(events)
	d.broadcastLocked(events)
	return nil
}

Review comment (suggestion):
```suggestion
		d.purge()
		d.minRev = minRev
		return
}
```

Code after:
	} else {
		d.activeWatchers[w] = startingRev
	}
}

func (d *demux) Unregister(w *watcher) {
	func() {
		d.mu.Lock()
		defer d.mu.Unlock()
		delete(d.activeWatchers, w)
		delete(d.laggingWatchers, w)
	}()
	w.Stop()
}

func (d *demux) Init(minRev int64) {
	d.mu.Lock()
	defer d.mu.Unlock()
	if d.minRev == 0 {
		// Watch started for empty demux
		d.minRev = minRev
		return
	}
	if d.maxRev == 0 {
		// Watch started on initialized demux that never got any event.
		d.purge()
		d.minRev = minRev
		return
	}
	if minRev == d.maxRev+1 {
		// Watch continuing from last revision it observed.
		return
	}
	// Watch opened on revision mismatching dmux last observed revision.
	d.purge()
	d.minRev = minRev
}

func (d *demux) Broadcast(resp clientv3.WatchResponse) error {
	events := resp.Events
	if len(events) == 0 {
		return nil
	}

	d.mu.Lock()
	defer d.mu.Unlock()
	err := validateRevisions(events, d.maxRev)
	if err != nil {
		return err
	}
	d.updateStoreLocked(events)
Repository: etcd-io/etcd
File: cache/demux_test.go (Go)

Code before:
		},
	}

	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			watcher := newWatcher(1, nil)
			d.Register(watcher, test.startingRev)

			activeRev, inActive := d.activeWatchers[watcher]
			laggingRev, inLagging := d.laggingWatchers[watcher]

			if test.expectActive {
				if !inActive {
					t.Errorf("expected watcher in active set, but not found")
				}
				if inLagging {
					t.Errorf("watcher unexpectedly found in lagging set")
				}
				if activeRev != test.expectedNextRev {
					t.Errorf("active nextRev = %d, want %d", activeRev, test.expectedNextRev)
				}
			} else {
				if !inLagging {
					t.Errorf("expected watcher in lagging set, but not found")
				}
				if inActive {
					t.Errorf("watcher unexpectedly found in active set")
				}
				if laggingRev != test.expectedNextRev {
					t.Errorf("lagging nextRev = %d, want %d", laggingRev, test.expectedNextRev)
				}
			}

			delete(d.activeWatchers, watcher)
			delete(d.laggingWatchers, watcher)
		})
	}
}

func TestBroadcastValidatesRevisions(t *testing.T) {
	tests := []struct {
		name         string
		initialRevs  []int64
		followupRevs []int64
		shouldError  bool
	}{
		{
			name:         "revisions below maxRev are rejected",
			initialRevs:  []int64{5, 6},
			followupRevs: []int64{4},
			shouldError:  true,

Review comment (bug):
```suggestion
		},
		{
			name:      "history overflow not continuous",
			capacity:  2,
			initRev:   2,
			eventRevs: []int64{4, 8, 16},
			wantMin:   5,
			wantMax:   16,
		},
```

Please remember that revisions are not guaranteed to be continious.

Code after:
		initRev      int64
		initialRevs  []int64
		followupRevs []int64
		want         want
	}{
		{
			name:        "history not full",
			capacity:    2,
			initRev:     1,
			initialRevs: []int64{2},
			want:        want{min: 1, max: 2, shouldError: false},
		},
		{
			name:        "history at exact capacity",
			capacity:    2,
			initRev:     1,
			initialRevs: []int64{2, 3},
			want:        want{min: 1, max: 3, shouldError: false},
		},
		{
			name:        "history overflow with eviction",
			capacity:    2,
			initRev:     1,
			initialRevs: []int64{2, 3, 4},
			want:        want{min: 3, max: 4, shouldError: false},
		},
		{
			name:        "history overflow not continuous",
			capacity:    2,
			initRev:     2,
			initialRevs: []int64{4, 8, 16},
			want:        want{min: 5, max: 16, shouldError: false},
		},
		{
			name:        "empty broadcast is no-op",
			capacity:    8,
			initRev:     10,
			initialRevs: []int64{},
			want:        want{min: 10, max: 0, shouldError: false},
		},
		{
			name:         "revisions below maxRev are rejected",
			capacity:     8,
			initRev:      4,
			initialRevs:  []int64{5, 6},
			followupRevs: []int64{4},
			want:         want{shouldError: true},
		},
		{
			name:         "revisions equal to maxRev are rejected",
			capacity:     8,
Repository: etcd-io/etcd
File: cache/demux_test.go (Go)

Code before:
			}
			if diff := cmp.Diff(tt.wantSizes, gotSizes); diff != "" {
				t.Fatalf("batch size mismatch (-want +got):\n%s", diff)
			}
		})
	}
}

func TestDemuxInitPurgeVsPreserve(t *testing.T) {
	type watcherCounts struct {
		active  int
		lagging int
	}
	type revisionRange struct {
		min, max int64
	}
	type historyRange struct {
		oldest, latest int64
	}
	tests := []struct {
		name        string
		setup       func(d *demux) watcherCounts
		initRev     int64
		shouldPurge bool
		wantRange   revisionRange
		wantHistory historyRange
	}{
		{
			name: "first init sets minRev and preserves empty state",
			setup: func(d *demux) watcherCounts {
				return watcherCounts{active: 0, lagging: 0}
			},
			initRev:     5,
			shouldPurge: false,
			wantRange:   revisionRange{min: 5, max: 0},
			wantHistory: historyRange{oldest: 0, latest: 0},
		},
		{
			name: "init with gap from maxRev purges watchers",
			setup: func(d *demux) watcherCounts {
				d.Init(10)
				watcher := newWatcher(1, nil)
				d.Register(watcher, 0)
				return watcherCounts{active: 1, lagging: 0}
			},
			initRev:     20,
			shouldPurge: true,
			wantRange:   revisionRange{min: 20, max: 0},
			wantHistory: historyRange{oldest: 0, latest: 0},
		},
		{

Review comment (suggestion):
```suggestion
		setup       func(d *demux) 
		initRev     int64
		shouldPurge bool
		wantRange   revisionRange
		wantHistory historyRange
		wantWatchers watcherCounts
```

Code after:
		t.Run(tt.name, func(t *testing.T) {
			d := newDemux(16, 10*time.Millisecond)
			w := newWatcher(len(tt.input)+1, nil)
			d.Register(w, 0)

			d.Broadcast(respWithEventRevs(tt.input...))

			gotRevs, gotSizes := readBatches(t, w, len(tt.wantRevs))

			if diff := cmp.Diff(tt.wantRevs, gotRevs); diff != "" {
				t.Fatalf("revision mismatch (-want +got):\n%s", diff)
			}
			if diff := cmp.Diff(tt.wantSizes, gotSizes); diff != "" {
				t.Fatalf("batch size mismatch (-want +got):\n%s", diff)
			}
		})
	}
}

func TestSlowWatcherResync(t *testing.T) {
	tests := []struct {
		name             string
		input            []int64
		wantInitialRevs  []int64
		wantInitialSizes []int
		wantResyncRevs   []int64
		wantResyncSizes  []int
	}{
		{
			name:             "single event overflow",
			input:            []int64{1, 2, 3},
			wantInitialRevs:  []int64{1},
			wantInitialSizes: []int{3},
			wantResyncRevs:   []int64{},
			wantResyncSizes:  []int{},
		},
		{
			name:             "multi events batch overflow",
			input:            []int64{10, 10, 11, 12, 12},
			wantInitialRevs:  []int64{10},
			wantInitialSizes: []int{5},
			wantResyncRevs:   []int64{},
			wantResyncSizes:  []int{},
		},
	}

	for _, tt := range tests {
		tt := tt
		t.Run(tt.name, func(t *testing.T) {
			d := newDemux(16, 10*time.Millisecond)
			w := newWatcher(1, nil)
Repository: etcd-io/etcd
File: cache/demux.go (Go)

Code before:
	defer d.mu.Unlock()
	d.purge()
}

func (d *demux) purge() {
	d.maxRev = 0
	d.minRev = 0
	d.history.RebaseHistory()
	for w := range d.activeWatchers {
		w.Stop()
	}
	for w := range d.laggingWatchers {
		w.Stop()
	}
	d.activeWatchers = make(map[*watcher]int64)
	d.laggingWatchers = make(map[*watcher]int64)
}

// Compact is called when etcd reports a compaction at compactRev to rebase history;
// it keeps provably-too-old watchers for later cancellation, stops others, and clients should resubscribe.
func (d *demux) Compact(compactRev int64) {
	d.mu.Lock()
	defer d.mu.Unlock()
	if compactRev < d.minRev {
		return
	}
	d.purge()
}

func (d *demux) resyncLaggingWatchers() {
	d.mu.Lock()
	defer d.mu.Unlock()

	if d.minRev == 0 {
		return
	}

	for w, nextRev := range d.laggingWatchers {
		if nextRev < d.minRev {
			w.Compact(nextRev)
			delete(d.laggingWatchers, w)
			continue
		}
		// TODO: re-enable key‐predicate in Filter when non‐zero startRev or performance tuning is needed
		enqueueFailed := false
		d.history.AscendGreaterOrEqual(nextRev, func(rev int64, eventBatch []*clientv3.Event) bool {
			if !w.enqueueEvent(eventBatch) { // buffer overflow: watcher still lagging
				enqueueFailed = true
				return false
			}
			nextRev = rev + 1

Review comment (suggestion):
```suggestion
```

Let's just skip this because it's not implemented properly

Code after:
// Purge stops all watchers and rebase history on watch errors
func (d *demux) Purge() {
	d.mu.Lock()
	defer d.mu.Unlock()
	d.purge()
}

func (d *demux) purge() {
	d.maxRev = 0
	d.minRev = 0
	d.history.RebaseHistory()
	for w := range d.activeWatchers {
		w.Stop()
	}
	for w := range d.laggingWatchers {
		w.Stop()
	}
	d.activeWatchers = make(map[*watcher]int64)
	d.laggingWatchers = make(map[*watcher]int64)
}

// Compact is called when etcd reports a compaction at compactRev to rebase history;
// it keeps provably-too-old watchers for later cancellation, stops others, and clients should resubscribe.
func (d *demux) Compact(compactRev int64) {
	d.mu.Lock()
	defer d.mu.Unlock()
	d.purge()
}

func (d *demux) resyncLaggingWatchers() {
	d.mu.Lock()
	defer d.mu.Unlock()

	if d.minRev == 0 {
		return
	}

	for w, nextRev := range d.laggingWatchers {
		if nextRev < d.minRev {
			w.Compact(nextRev)
			delete(d.laggingWatchers, w)
			continue
		}
		// TODO: re-enable key‐predicate in Filter when non‐zero startRev or performance tuning is needed
		enqueueFailed := false
		d.history.AscendGreaterOrEqual(nextRev, func(rev int64, eventBatch []*clientv3.Event) bool {
			if !w.enqueueEvent(eventBatch) { // buffer overflow: watcher still lagging
				enqueueFailed = true
				return false
			}
			nextRev = rev + 1
Repository: etcd-io/etcd
File: cache/demux_test.go (Go)

Code before:
			capacity:  8,
			initRev:   10,
			eventRevs: []int64{},
			wantMin:   10,
			wantMax:   0,
		},
	}

	for _, tt := range tests {
		tt := tt
		t.Run(tt.name, func(t *testing.T) {
			d := newDemux(tt.capacity, 10*time.Millisecond)
			d.Init(tt.initRev)

			if err := d.Broadcast(respWithEventRevs(tt.eventRevs...)); err != nil {
				t.Fatalf("Broadcast(%v) error: %v", tt.eventRevs, err)
			}

			if d.minRev != tt.wantMin || d.maxRev != tt.wantMax {
				t.Fatalf("range (minRev, maxRev) got=(%d,%d) want=(%d,%d)", d.minRev, d.maxRev, tt.wantMin, tt.wantMax)
			}
		})
	}
}

func TestBroadcastValidatesRevisions(t *testing.T) {
	tests := []struct {
		name         string
		initialRevs  []int64
		followupRevs []int64
		shouldError  bool
	}{
		{
			name:         "revisions below maxRev are rejected",
			initialRevs:  []int64{5, 6},
			followupRevs: []int64{4},
			shouldError:  true,
		},
		{
			name:         "revisions equal to maxRev are rejected",
			initialRevs:  []int64{5, 6},
			followupRevs: []int64{6},
			shouldError:  true,
		},
		{
			name:         "revisions above maxRev are accepted",
			initialRevs:  []int64{5, 6},
			followupRevs: []int64{9, 14},
			shouldError:  false,
		},
	}

Review comment (bug):
It's better to have one test with large table of scenarios than having multiple tests that have small differences. Here fact that Broadcast return error can be also validated in TestBroadcastMinMaxRange. I would recommend to merge `TestBroadcastMinMaxRange` and `TestBroadcastValidatesRevisions` and create `TestBroadcast`. This gives one canonical pattern for writing test for the method, and allows to easily confirm if all edge cases are covered. 

Code after:
			capacity:    2,
			initRev:     1,
			initialRevs: []int64{2, 3, 4},
			want:        want{min: 3, max: 4, shouldError: false},
		},
		{
			name:        "history overflow not continuous",
			capacity:    2,
			initRev:     2,
			initialRevs: []int64{4, 8, 16},
			want:        want{min: 5, max: 16, shouldError: false},
		},
		{
			name:        "empty broadcast is no-op",
			capacity:    8,
			initRev:     10,
			initialRevs: []int64{},
			want:        want{min: 10, max: 0, shouldError: false},
		},
		{
			name:         "revisions below maxRev are rejected",
			capacity:     8,
			initRev:      4,
			initialRevs:  []int64{5, 6},
			followupRevs: []int64{4},
			want:         want{shouldError: true},
		},
		{
			name:         "revisions equal to maxRev are rejected",
			capacity:     8,
			initRev:      4,
			initialRevs:  []int64{5, 6},
			followupRevs: []int64{6},
			want:         want{shouldError: true},
		},
		{
			name:         "revisions above maxRev are accepted",
			capacity:     8,
			initRev:      4,
			initialRevs:  []int64{5, 6},
			followupRevs: []int64{9, 14, 17},
			want:         want{min: 4, max: 17, shouldError: false},
		},
	}

	for _, tt := range tests {
		tt := tt
		t.Run(tt.name, func(t *testing.T) {
			d := newDemux(tt.capacity, 10*time.Millisecond)
			d.Init(tt.initRev)
Repository: etcd-io/etcd
File: tests/common/e2e_test.go (Go)

Code before:
	if !ok {
		return false
	}
	parsed, err := strconv.ParseBool(v)
	if err != nil {
		fmt.Printf("Invalid %s value %q: %v\n", minimalE2eEnabledEnvVarName, v, err)
		return false
	}
	return parsed
}

func e2eClusterTestCases() []testCase {
	minimalTestCases := []testCase{
		{
			name:   "NoTLS",
			config: config.ClusterConfig{ClusterSize: 1},
		},
		{
			name:   "PeerTLS",
			config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.ManualTLS},
		},
		{
			name:   "ClientTLS",
			config: config.ClusterConfig{ClusterSize: 1, ClientTLS: config.ManualTLS},
		},
	}

	if minimalE2eEnabled() {
		return minimalTestCases
	}

	tcs := append(minimalTestCases,
		testCase{
			name:   "PeerAutoTLS",
			config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.AutoTLS},
		},
		testCase{
			name:   "ClientAutoTLS",
			config: config.ClusterConfig{ClusterSize: 1, ClientTLS: config.AutoTLS},
		})

	if fileutil.Exist(e2e.BinPath.EtcdLastRelease) {
		tcs = append(tcs,
			testCase{
				name: "MinorityLastVersion",
				config: config.ClusterConfig{
					ClusterSize: 3,
					ClusterContext: &e2e.ClusterContext{
						Version: e2e.MinorityLastVersion,
					},
				},

Review comment (suggestion):
let's get a result how much time we can save first.
```suggestion
	if true {
		return minimalTestCases
	}
```

We also need to update the workflow to set the environment variable for e2e test

 https://github.com/kubernetes/test-infra/blob/master/config/jobs/etcd/etcd-presubmits.yaml 

cc @ivanvc 

Code after:
	if !ok {
		return false
	}
	parsed, err := strconv.ParseBool(v)
	if err != nil {
		fmt.Printf("Invalid %s value %q: %v\n", minimalE2eEnabledEnvVarName, v, err)
		return false
	}
	return parsed
}

func e2eClusterTestCases() []testCase {
	minimalTestCases := []testCase{
		{
			name:   "NoTLS",
			config: config.ClusterConfig{ClusterSize: 1},
		},
		{
			name:   "PeerTLS and ClientTLS",
			config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.ManualTLS, ClientTLS: config.ManualTLS},
		},
	}

	if minimalE2eEnabled() {
		return minimalTestCases
	}

	tcs := append(minimalTestCases,
		testCase{
			name:   "PeerAutoTLS and ClientAutoTLS",
			config: config.ClusterConfig{ClusterSize: 3, PeerTLS: config.AutoTLS, ClientTLS: config.AutoTLS},
		},
	)

	if fileutil.Exist(e2e.BinPath.EtcdLastRelease) {
		tcs = append(tcs,
			testCase{
				name: "MinorityLastVersion",
				config: config.ClusterConfig{
					ClusterSize: 3,
					ClusterContext: &e2e.ClusterContext{
						Version: e2e.MinorityLastVersion,
					},
				},
			},
			testCase{
				name: "QuorumLastVersion",
				config: config.ClusterConfig{
					ClusterSize: 3,
					ClusterContext: &e2e.ClusterContext{
						Version: e2e.QuorumLastVersion,