2021-05-02 20:33:13 +00:00
|
|
|
package diagnose
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
2021-05-25 22:23:20 +00:00
|
|
|
"time"
|
2021-05-02 20:33:13 +00:00
|
|
|
|
|
|
|
"github.com/hashicorp/vault/sdk/physical"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStorageTimeout(t *testing.T) {
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
errSubString string
|
|
|
|
mb physical.Backend
|
|
|
|
}{
|
|
|
|
{
|
2021-05-25 22:23:20 +00:00
|
|
|
errSubString: LatencyWarning,
|
2021-05-02 20:33:13 +00:00
|
|
|
mb: mockStorageBackend{callType: timeoutCallWrite},
|
|
|
|
},
|
|
|
|
{
|
2021-05-25 22:23:20 +00:00
|
|
|
errSubString: LatencyWarning,
|
2021-05-02 20:33:13 +00:00
|
|
|
mb: mockStorageBackend{callType: timeoutCallRead},
|
|
|
|
},
|
|
|
|
{
|
2021-05-25 22:23:20 +00:00
|
|
|
errSubString: LatencyWarning,
|
2021-05-02 20:33:13 +00:00
|
|
|
mb: mockStorageBackend{callType: timeoutCallDelete},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
errSubString: storageErrStringWrite,
|
|
|
|
mb: mockStorageBackend{callType: errCallWrite},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
errSubString: storageErrStringDelete,
|
|
|
|
mb: mockStorageBackend{callType: errCallDelete},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
errSubString: storageErrStringRead,
|
|
|
|
mb: mockStorageBackend{callType: errCallRead},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
errSubString: wrongRWValsPrefix,
|
|
|
|
mb: mockStorageBackend{callType: badReadCall},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
2021-05-25 22:23:20 +00:00
|
|
|
var outErr error
|
|
|
|
var dur time.Duration
|
|
|
|
uuid := "foo"
|
|
|
|
backendCallType := tc.mb.(mockStorageBackend).callType
|
|
|
|
if callTypeToOp(backendCallType) == readOp {
|
|
|
|
dur, outErr = EndToEndLatencyCheckRead(context.Background(), uuid, tc.mb)
|
|
|
|
}
|
|
|
|
if callTypeToOp(backendCallType) == writeOp {
|
|
|
|
dur, outErr = EndToEndLatencyCheckWrite(context.Background(), uuid, tc.mb)
|
|
|
|
}
|
|
|
|
if callTypeToOp(backendCallType) == deleteOp {
|
|
|
|
dur, outErr = EndToEndLatencyCheckDelete(context.Background(), uuid, tc.mb)
|
|
|
|
}
|
|
|
|
|
2021-05-02 20:33:13 +00:00
|
|
|
if tc.errSubString == "" && outErr == nil {
|
|
|
|
// this is the success case where the Storage Latency check passes
|
|
|
|
continue
|
|
|
|
}
|
2021-05-25 22:23:20 +00:00
|
|
|
if tc.errSubString == LatencyWarning && dur > time.Duration(0) {
|
|
|
|
// this is the success case where the Storage Latency check successfully returns nonzero duration
|
|
|
|
continue
|
|
|
|
}
|
2021-05-02 20:33:13 +00:00
|
|
|
if !strings.Contains(outErr.Error(), tc.errSubString) {
|
|
|
|
t.Errorf("wrong error: expected %s to be contained in %s", tc.errSubString, outErr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|