mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
d7b3589dbd
### Describe Your Changes Related issue: #7199 This is the initial version of the integration tests for cluster. See `README.md` for details. Currently cluster only, but it can also be used for vm-single if needed. The code has been added to the apptest package that resides in the root directory of the VM codebase. This is done to exclude the integration tests from regular testing build targets because: - Most of the test variants do not apply to integration testing (such as pure or race). - The integtation tests may also be slow because each test must wait for 2 seconds so vmstorage flushes pending content). It may be okay when there are a few tests but when there is a 100 of them running tests will require much more time which will affect the developer wait time and CI workflows. - Finally, the integration tests may be flaky especially short term. An alternative approach would be placing apptest under app package and exclude apptest from packages under test, but that is not trivial. The integration tests rely on retrieving some application runtime info from the application logs, namely the application's host:port. Therefore some changes to lib/httpserver/httpserver.go were necessary, such as reporting the effective host:port instead the one from the flag. ### Checklist The following checks are **mandatory**: - [x] My change adheres [VictoriaMetrics contributing guidelines](https://docs.victoriametrics.com/contributing/). --------- Signed-off-by: Artem Fetishev <rtm@victoriametrics.com>
42 lines
1,023 B
Go
42 lines
1,023 B
Go
package apptest
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fs"
|
|
)
|
|
|
|
// TestCase holds the state and defines clean-up procedure common for all test
|
|
// cases.
|
|
type TestCase struct {
|
|
t *testing.T
|
|
cli *Client
|
|
}
|
|
|
|
// NewTestCase creates a new test case.
|
|
func NewTestCase(t *testing.T) *TestCase {
|
|
return &TestCase{t, NewClient()}
|
|
}
|
|
|
|
// Dir returns the directory name that should be used by as the -storageDataDir.
|
|
func (tc *TestCase) Dir() string {
|
|
return tc.t.Name()
|
|
}
|
|
|
|
// Client returns an instance of the client that can be used for interacting with
|
|
// the app(s) under test.
|
|
func (tc *TestCase) Client() *Client {
|
|
return tc.cli
|
|
}
|
|
|
|
// Close performs the test case clean up, such as closing all client connections
|
|
// and removing the -storageDataDir directory.
|
|
//
|
|
// Note that the -storageDataDir is not removed in case of test case failure to
|
|
// allow for furher manual debugging.
|
|
func (tc *TestCase) Close() {
|
|
tc.cli.CloseConnections()
|
|
if !tc.t.Failed() {
|
|
fs.MustRemoveAll(tc.Dir())
|
|
}
|
|
}
|