-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release-21.0] Fix panic in vttablet when closing topo server twice (#…
…17094) (#17122) Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
ebfed08
commit 5fbbb8e
Showing
3 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
Copyright 2024 The Vitess Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cli | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"vitess.io/vitess/go/vt/topo" | ||
"vitess.io/vitess/go/vt/topo/memorytopo" | ||
) | ||
|
||
// TestRunFailsToStartTabletManager tests the code path in 'run' where we fail to start the TabletManager | ||
// this is done by starting vttablet without a cnf file but requesting it to restore from backup. | ||
// When starting, the TabletManager checks if it needs to restore, in tm.handleRestore but this step will | ||
// fail if we do not provide a cnf file and if the flag --restore_from_backup is provided. | ||
func TestRunFailsToStartTabletManager(t *testing.T) { | ||
ts, factory := memorytopo.NewServerAndFactory(context.Background(), "cell") | ||
topo.RegisterFactory("test", factory) | ||
|
||
args := append([]string{}, os.Args...) | ||
t.Cleanup(func() { | ||
ts.Close() | ||
tabletPath = "" | ||
os.Args = append([]string{}, args...) | ||
}) | ||
|
||
os.Args = []string{"vttablet", | ||
"--topo_implementation", "test", "--topo_global_server_address", "localhost", "--topo_global_root", "cell", | ||
"--db_host", "localhost", "--db_port", "3306", | ||
"--tablet-path", "cell-1", "--init_keyspace", "ks", "--init_shard", "0", "--init_tablet_type", "replica", | ||
"--restore_from_backup", | ||
} | ||
|
||
// Creating and canceling the context so that pending tasks in tm_init gets canceled before we close the topo server | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
err := Main.ExecuteContext(ctx) | ||
require.ErrorContains(t, err, "you cannot enable --restore_from_backup without a my.cnf file") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters