Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/actions/prepare-ee-test-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: "Prepare test environment with Tarantool EE"
description: "Prepares test environment with Tarantool EE"

inputs:
sdk-version:
required: true
type: string
sdk-build:
required: false
type: string
default: release
sdk-gc:
required: false
type: string
default: gc64
sdk-download-token:
required: true
type: string

runs:
using: "composite"
steps:
- name: Cache Tarantool SDK
id: cache-sdk
uses: actions/cache@v3
with:
path: tarantool-enterprise
key: ${{ matrix.sdk-version }}

- name: Download Tarantool SDK
run: |
ARCHIVE_NAME=tarantool-enterprise-sdk-${{ inputs.sdk-gc }}-${{ inputs.sdk-version }}.tar.gz
ARCHIVE_PATH=$(echo ${{ inputs.sdk-version }} | sed -rn \
's/^([0-9]+)\.([0-9]+)\.([0-9]+-){2}([a-z0-9]+-)?r[0-9]+\.([a-z]+)\.([a-z0-9_]+)$/${{ inputs.sdk-build }}\/\5\/\6\/\1\.\2/p')
curl -O -L \
https://${{ inputs.sdk-download-token }}@download.tarantool.io/enterprise/${ARCHIVE_PATH}/${ARCHIVE_NAME}
if [ $(stat -c%s "${ARCHIVE_NAME}") -eq 0 ]; then
echo "Failed to download Tarantool EE SDK: '${ARCHIVE_PATH}/${ARCHIVE_NAME}'"
exit 1
fi
tar -xzf ${ARCHIVE_NAME}
rm -f ${ARCHIVE_NAME}
source tarantool-enterprise/env.sh
shell: bash

- name: Add SDK to PATH and set TARANTOOL_SDK_PATH variable
run: |
SDK_PATH="$(realpath tarantool-enterprise)"
echo "${SDK_PATH}" >> ${GITHUB_PATH}
echo "TARANTOOL_SDK_PATH=${SDK_PATH}" >> ${GITHUB_ENV}
shell: bash
57 changes: 57 additions & 0 deletions .github/workflows/tcs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: tcs.yaml
on:
pull_request_target:
types: [ labeled ]

env:
# Note: Use exactly match version of tool, to avoid unexpected issues with test on CI.
GO_VERSION: '1.24.9'

jobs:
full-ci-ee:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need tests with ce too for a some common purposes. The idea here:

  1. A user makes pull requests.
  2. We run all tests exclude integration tests with tcs as a first check.
  3. A user with write access sets the full-ci label.
  4. We run addition tests on Tarantool EE to ensure that everything work fine.

The pattern is used across our libraries. So, please, implement it here too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already implemented.

# Tests will run only when the pull request is labeled with `full-ci`. To
# avoid security problems, the label must be reset manually for every run.
#
# We need to use `pull_request_target` because it has access to base
# repository secrets unlike `pull_request`.
if: (github.event_name == 'push') ||
(github.event_name == 'pull_request_target' &&
github.event.action == 'labeled' &&
github.event.label.name == 'full-ci') ||
(github.event_name == 'pull_request' &&
github.event.action == 'synchronize' &&
github.event.pull_request.head.repo.full_name == github.repository &&
contains(github.event.pull_request.labels.*.name, 'full-ci'))
runs-on: ubuntu-22.04
strategy:
matrix:
sdk-version:
- "3.5.0-0-r70.linux.x86_64"
fail-fast: false
steps:
# `ref` as merge request is needed for pull_request_target because this
# target runs in the context of the base commit of the pull request.
- uses: actions/checkout@v4
if: github.event_name == 'pull_request_target'
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}

- uses: actions/checkout@v4
if: github.event_name != 'pull_request_target'
with:
fetch-depth: 0

- name: Prepare EE env
uses: ./.github/actions/prepare-ee-test-env
with:
sdk-version: '${{ matrix.sdk-version }}'
sdk-download-token: '${{ secrets.SDK_DOWNLOAD_TOKEN }}'

- name: Integration tests
run:
go test ./... -count=1 -v
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add tests run with race detection too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


- name: Integration tests
run:
go test ./... -count=100 -v -race
12 changes: 12 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ linters:
- path: _test.go
linters:
- wrapcheck
- err113
- funlen

settings:
varnamelen:
ignore-names:
- tt
ignore-decls:
- mc *minimock.Controller
godot:
scope: all
lll:
Expand All @@ -50,10 +57,15 @@ linters:
- "go.etcd.io/etcd/client/v3"
- "github.com/tarantool/go-tarantool/v2"
- "github.com/tarantool/go-option"
- "github.com/vmihailenco/msgpack/v5"
test:
files:
- "$test"
allow:
- $gostd
- "github.com/tarantool/go-storage"
- "github.com/stretchr/testify"
- "github.com/tarantool/go-tarantool/v2"
- "github.com/tarantool/go-iproto"
- "github.com/vmihailenco/msgpack/v5"
- "github.com/gojuno/minimock/v3"
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ codespell:
.PHONY: test
test:
@echo "Running tests"
@go test ./... -count=1
@go test ./... -count=1 -v

.PHONY: testrace
testrace:
@echo "Running tests with race flag"
@go test ./... -count=100 -race
@go test ./... -count=100 -race -v

.PHONY: coverage
coverage:
Expand Down
4 changes: 3 additions & 1 deletion driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ type Driver interface {

// Watch establishes a watch stream for changes to a specific key or prefix.
// The returned channel will receive events as changes occur.
Watch(ctx context.Context, key []byte, opts ...watch.Option) <-chan watch.Event
// The returned cleanup function should be called to stop the watch and release resources.
// An error is returned if the watch could not be established.
Watch(ctx context.Context, key []byte, opts ...watch.Option) (<-chan watch.Event, func(), error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a tests that the TCS driver implements the Driver interface.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used, instead:

_ driver.Driver = &Driver{} //nolint:exhaustruct

}
2 changes: 1 addition & 1 deletion driver/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ func (d Driver) Execute(

// Watch monitors changes to a specific key and returns a stream of events.
// It supports optional watch configuration through the opts parameter.
func (d Driver) Watch(_ context.Context, _ []byte, _ ...watch.Option) <-chan watch.Event {
func (d Driver) Watch(_ context.Context, _ []byte, _ ...watch.Option) (<-chan watch.Event, func(), error) {
panic("implement me")
}
85 changes: 85 additions & 0 deletions driver/tcs/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package tcs

import (
"fmt"
)

// DecodingError represents an error that occurs during decoding operations.
type DecodingError struct {
ObjectType string
Text string
Err error
}

// Error returns the error message.
func (e DecodingError) Error() string {
suffix := e.ObjectType
if e.Text != "" {
suffix = fmt.Sprintf("%s, %s", suffix, e.Text)
}

return fmt.Sprintf("failed to decode %s: %s", suffix, e.Err)
}

func (e DecodingError) Unwrap() error {
return e.Err
}

// NewTxnOpResponseDecodingError returns a new txnOpResponse decoding error.
func NewTxnOpResponseDecodingError(err error) error {
if err == nil {
return nil
}

return DecodingError{
ObjectType: "txnOpResponse",
Text: "",
Err: err,
}
}

// EncodingError represents an error that occurs during encoding operations.
type EncodingError struct {
ObjectType string
Text string
Err error
}

// Error returns the error message.
func (e EncodingError) Error() string {
if e.Text == "" {
return fmt.Sprintf("failed to encode %s: %s", e.ObjectType, e.Err)
}

return fmt.Sprintf("failed to encode %s, %s: %s", e.ObjectType, e.Text, e.Err)
}

func (e EncodingError) Unwrap() error {
return e.Err
}

// NewOperationEncodingError returns a new operation encoding error.
func NewOperationEncodingError(text string, err error) error {
if err == nil {
return nil
}

return EncodingError{
ObjectType: "operation",
Text: text,
Err: err,
}
}

// NewPredicateEncodingError returns a new predicate encoding error.
func NewPredicateEncodingError(text string, err error) error {
if err == nil {
return nil
}

return EncodingError{
ObjectType: "predicate",
Text: text,
Err: err,
}
}
Loading
Loading