Skip to content

Commit 2cf6fa8

Browse files
committed
upgrade_manager: fix ListBetweenOverride for some tests
`ListBetweenOverride` is used by tests to override `clusterversion.ListBetween` when we are not testing with real versions. This function is supposed to return versions that are *after* `from`; some tests return `from` in the result which causes some failures when trying to mint the 25.1 release. This commit fixes these and adds validation of the `ListBetweenOverride` result. Epic: none Release note: None
1 parent 9893597 commit 2cf6fa8

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

pkg/upgrade/upgradebase/testing_knobs.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ const (
2727
// are useful for testing.
2828
type TestingKnobs struct {
2929

30-
// ListBetweenOverride injects an override for `clusterversion.ListBetween()
31-
// in order to run upgrades corresponding to versions which do not
32-
// actually exist.
30+
// ListBetweenOverride injects an override for clusterversion.ListBetween() in
31+
// order to run upgrades corresponding to versions which do not actually
32+
// exist. This function has to return versions in the range (from, to].
3333
ListBetweenOverride func(from, to roachpb.Version) []roachpb.Version
3434

3535
// RegistryOverride is used to inject upgrades for specific cluster versions.

pkg/upgrade/upgrademanager/manager.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,14 @@ func (m *Manager) getRunningMigrationJob(
828828

829829
func (m *Manager) listBetween(from roachpb.Version, to roachpb.Version) []roachpb.Version {
830830
if m.knobs.ListBetweenOverride != nil {
831-
return m.knobs.ListBetweenOverride(from, to)
831+
result := m.knobs.ListBetweenOverride(from, to)
832+
// Sanity check result to catch invalid overrides.
833+
for _, v := range result {
834+
if v.LessEq(from) || to.Less(v) {
835+
panic(fmt.Sprintf("ListBetweenOverride(%s, %s) returned invalid version %s", from, to, v))
836+
}
837+
}
838+
return result
832839
}
833840
return clusterversion.ListBetween(from, to)
834841
}

pkg/upgrade/upgrademanager/manager_external_test.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func TestAlreadyRunningJobsAreHandledProperly(t *testing.T) {
100100
},
101101
UpgradeManager: &upgradebase.TestingKnobs{
102102
ListBetweenOverride: func(from, to roachpb.Version) []roachpb.Version {
103-
return []roachpb.Version{from, to}
103+
return []roachpb.Version{to}
104104
},
105105
RegistryOverride: func(v roachpb.Version) (upgradebase.Upgrade, bool) {
106106
if v != endCV.Version() {
@@ -399,7 +399,7 @@ func TestMigrateUpdatesReplicaVersion(t *testing.T) {
399399
},
400400
UpgradeManager: &upgradebase.TestingKnobs{
401401
ListBetweenOverride: func(from, to roachpb.Version) []roachpb.Version {
402-
return []roachpb.Version{from, to}
402+
return []roachpb.Version{to}
403403
},
404404
RegistryOverride: func(cv roachpb.Version) (upgradebase.Upgrade, bool) {
405405
if cv != endCV {
@@ -504,7 +504,13 @@ func TestConcurrentMigrationAttempts(t *testing.T) {
504504
},
505505
UpgradeManager: &upgradebase.TestingKnobs{
506506
ListBetweenOverride: func(from, to roachpb.Version) []roachpb.Version {
507-
return versions
507+
var res []roachpb.Version
508+
for _, v := range versions {
509+
if from.Less(v) && v.LessEq(to) {
510+
res = append(res, v)
511+
}
512+
}
513+
return res
508514
},
509515
RegistryOverride: func(cv roachpb.Version) (upgradebase.Upgrade, bool) {
510516
return upgrade.NewSystemUpgrade("test", cv, func(
@@ -556,7 +562,7 @@ func TestConcurrentMigrationAttempts(t *testing.T) {
556562
for k, c := range migrationRunCounts {
557563
require.Equalf(t, 1, c, "version: %v", k)
558564
}
559-
require.Len(t, migrationRunCounts, len(versions))
565+
require.Len(t, migrationRunCounts, len(versions)-1)
560566
}
561567

562568
// TestPauseMigration ensures that upgrades can indeed be paused and that
@@ -592,7 +598,13 @@ func TestPauseMigration(t *testing.T) {
592598
},
593599
UpgradeManager: &upgradebase.TestingKnobs{
594600
ListBetweenOverride: func(from, to roachpb.Version) []roachpb.Version {
595-
return []roachpb.Version{from, to}
601+
// We expect calls to ListBetween to be made for (0.0, startCV] and (startCV, endCV].
602+
if to != startCV.Version() {
603+
if from != startCV.Version() || to != endCV.Version() {
604+
panic(fmt.Sprintf("unexpected versions %v, %v\n", from, to))
605+
}
606+
}
607+
return []roachpb.Version{to}
596608
},
597609
RegistryOverride: func(cv roachpb.Version) (upgradebase.Upgrade, bool) {
598610
if cv != endCV.Version() {

pkg/upgrade/upgrades/schema_changes_external_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,7 @@ func testMigrationWithFailures(
351351
},
352352
UpgradeManager: &upgradebase.TestingKnobs{
353353
ListBetweenOverride: func(from, to roachpb.Version) []roachpb.Version {
354-
return []roachpb.Version{
355-
endCV,
356-
}
354+
return []roachpb.Version{to}
357355
},
358356
RegistryOverride: func(cv roachpb.Version) (upgradebase.Upgrade, bool) {
359357
if cv.Equal(endCV) {
@@ -364,7 +362,7 @@ func testMigrationWithFailures(
364362
upgrade.RestoreActionNotRequired("test"),
365363
), true
366364
}
367-
panic("unexpected version")
365+
return nil, false
368366
}},
369367
},
370368
},

0 commit comments

Comments
 (0)