@@ -23,6 +23,7 @@ import (
23
23
"os"
24
24
"os/exec"
25
25
"path/filepath"
26
+ "runtime"
26
27
"strings"
27
28
"sync"
28
29
"testing"
@@ -355,8 +356,8 @@ func TestRestartNode(t *testing.T) {
355
356
}
356
357
357
358
log .Printf ("Stopping Node 2" )
358
- require .NoError (t , ts .StopNode (2 ))
359
- for i := 0 ; i < 2 ; i ++ {
359
+ require .NoError (t , ts .StopNode (0 ))
360
+ for i := 1 ; i < 3 ; i ++ {
360
361
url := ts .PGURLForNode (i )
361
362
362
363
db , err := sql .Open ("postgres" , url .String ())
@@ -368,8 +369,8 @@ func TestRestartNode(t *testing.T) {
368
369
require .NoError (t , db .Close ())
369
370
}
370
371
371
- require .NoError (t , ts .StartNode (2 ))
372
- require .NoError (t , ts .WaitForInitFinishForNode (2 ))
372
+ require .NoError (t , ts .StartNode (0 ))
373
+ require .NoError (t , ts .WaitForInitFinishForNode (0 ))
373
374
374
375
for i := 0 ; i < 3 ; i ++ {
375
376
url := ts .PGURLForNode (i )
@@ -382,6 +383,15 @@ func TestRestartNode(t *testing.T) {
382
383
require .NoError (t , err )
383
384
require .NoError (t , db .Close ())
384
385
}
386
+
387
+ url := ts .PGURLForNode (0 )
388
+ db , err := sql .Open ("postgres" , url .String ())
389
+ require .NoError (t , err )
390
+ var out int
391
+ row := db .QueryRow ("SELECT 1" )
392
+ err = row .Scan (& out )
393
+ require .NoError (t , err )
394
+ require .NoError (t , db .Close ())
385
395
}
386
396
387
397
func downloadBinaryTest (filepath string , url string ) error {
@@ -405,12 +415,25 @@ func downloadBinaryTest(filepath string, url string) error {
405
415
}
406
416
407
417
func TestUpgradeNode (t * testing.T ) {
408
- t .Skip ("doesn't work on linux" )
409
- binary21_2 := "cockroach-v21.2.12.darwin-10.9-amd64"
410
- binary22_1 := "cockroach-v22.1.0.darwin-10.9-amd64"
411
- getMacBinary := func (fileName string ) {
418
+ oldVersion := "v21.2.12"
419
+ newVersion := "v22.1.6"
420
+
421
+ var oldVersionBinary , newVersionBinary string
422
+ switch runtime .GOOS {
423
+ case "darwin" :
424
+ oldVersionBinary = fmt .Sprintf ("cockroach-%s.darwin-10.9-amd64" , oldVersion )
425
+ newVersionBinary = fmt .Sprintf ("cockroach-%s.darwin-10.9-amd64" , newVersion )
426
+ case "linux" :
427
+ oldVersionBinary = fmt .Sprintf ("cockroach-%s.linux-amd64" , oldVersion )
428
+ newVersionBinary = fmt .Sprintf ("cockroach-%s.linux-amd64" , newVersion )
429
+ default :
430
+ t .Fatalf ("unsupported os for test: %s" , runtime .GOOS )
431
+ }
432
+
433
+ getBinary := func (fileName string ) {
412
434
require .NoError (t , exec .Command ("mkdir" , "./temp_binaries" ).Start ())
413
- require .NoError (t , downloadBinaryTest (fmt .Sprintf ("./temp_binaries/%s.tgz" , fileName ), fmt .Sprintf ("https://binaries.cockroachdb.com/%s.tgz" , fileName )))
435
+ require .NoError (t , downloadBinaryTest (fmt .Sprintf ("./temp_binaries/%s.tgz" , fileName ),
436
+ fmt .Sprintf ("https://binaries.cockroachdb.com/%s.tgz" , fileName )))
414
437
tarCmd := exec .Command ("tar" , "-zxvf" , fmt .Sprintf ("./temp_binaries/%s.tgz" , fileName ), "-C" , "./temp_binaries" )
415
438
require .NoError (t , tarCmd .Start ())
416
439
require .NoError (t , tarCmd .Wait ())
@@ -420,18 +443,18 @@ func TestUpgradeNode(t *testing.T) {
420
443
require .NoError (t , exec .Command ("rm" , "-rf" , "./temp_binaries" ).Start ())
421
444
}()
422
445
423
- getMacBinary ( binary21_2 )
424
- getMacBinary ( binary22_1 )
446
+ getBinary ( oldVersionBinary )
447
+ getBinary ( newVersionBinary )
425
448
426
- absFilePath21_2 , err := filepath .Abs (fmt .Sprintf ("./temp_binaries/%s/cockroach" , binary21_2 ))
449
+ absPathOldBinary , err := filepath .Abs (fmt .Sprintf ("./temp_binaries/%s/cockroach" , oldVersionBinary ))
427
450
require .NoError (t , err )
428
- absFilePath22_1 , err := filepath .Abs (fmt .Sprintf ("./temp_binaries/%s/cockroach" , binary22_1 ))
451
+ absPathNewBinary , err := filepath .Abs (fmt .Sprintf ("./temp_binaries/%s/cockroach" , newVersionBinary ))
429
452
require .NoError (t , err )
430
453
431
454
ts , err := testserver .NewTestServer (
432
455
testserver .ThreeNodeOpt (),
433
- testserver .CockroachBinaryPathOpt (absFilePath21_2 ),
434
- testserver .UpgradeCockroachBinaryPathOpt (absFilePath22_1 ),
456
+ testserver .CockroachBinaryPathOpt (absPathOldBinary ),
457
+ testserver .UpgradeCockroachBinaryPathOpt (absPathNewBinary ),
435
458
testserver .StoreOnDiskOpt (),
436
459
)
437
460
require .NoError (t , err )
@@ -444,6 +467,9 @@ func TestUpgradeNode(t *testing.T) {
444
467
url := ts .PGURL ()
445
468
db , err := sql .Open ("postgres" , url .String ())
446
469
require .NoError (t , err )
470
+ defer func () {
471
+ require .NoError (t , db .Close ())
472
+ }()
447
473
448
474
var version string
449
475
row := db .QueryRow ("SHOW CLUSTER SETTING version" )
0 commit comments