Skip to content

Commit

Permalink
*: add mysql client test (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox authored Jul 10, 2023
1 parent 2726b7a commit 0c03603
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
${{ runner.os }}-go-
- name : "tidy mod if needed"
id: tidy
if: ${{ inputs.target == 'cmd' }}
if: ${{ inputs.target == 'cmd' && runner.os != 'Windows' }}
uses: evantorrie/mott-the-tidier@v1-beta
with:
gomods: |
Expand Down
73 changes: 73 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: integration
on:
workflow_call:
inputs:
debug:
type: boolean
description: "set tmate on failure"
required: true
ref:
type: string
description: "checkout specific ref"
required: true

defaults:
run:
shell: bash

jobs:
integration:
runs-on: "ubuntu-latest"
steps:
- name: "checkout repo"
uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}
- name: "checkout mysql"
uses: actions/checkout@v3
with:
repository: "xhebox/mysql-server"
path: "mysql-server"
- name: "setup golang"
uses: actions/setup-go@v3
with:
go-version-file: go.mod
check-latest: true
- name: "set vars"
id: cache
run: |
echo "::set-output name=go_cache::$(go env GOCACHE)"
echo "::set-output name=go_mod_cache::$(go env GOMODCACHE)"
- name: "try to use build cache"
uses: actions/cache@v3
with:
path: |
${{ steps.cache.outputs.go_cache }}
${{ steps.cache.outputs.go_mod_cache }}
key: ${{ runner.os }}-go-${{ inputs.target == 'cache' && github.run_id || hashFiles('**/go.sum')}}
restore-keys: |
${{ runner.os }}-go-
- name: build tiproxy
run: make cmd
- name: build mysql client test
run: |
cmake -Bbuild -DWITHOUT_SERVER=on -DWITH_UNIT_TESTS=off mysql-server
cmake --build build -t mysql_client_test
- name: setup & test
run: |
sed -i 's/# pd-addrs = "127.0.0.1:2379"/pd-addrs = ""/' conf/proxy.toml
sed -i 's/# auto-certs = true/auto-certs = true/' conf/proxy.toml
sed -i 's/4000/3306/' conf/namespace/example.toml
./bin/tiproxy --config conf/proxy.toml &
sudo systemctl start mysql
sleep 1
./bin/tiproxyctl -k namespace import conf/namespace/
./bin/tiproxyctl -k namespace commit default
sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';FLUSH PRIVILEGES"
mysql -h 127.0.0.1 -P 3306 -u root -proot -e "drop database if exists client_test_db; create database client_test_db; create database test"
# failed:
# test_view_sp_list_fields test_prepare_grant test_bug5315 test_change_user test_bug30472 test_bug20023 test_bug53371 test_bug31418 test_bug31669 test_wl4435 test_wl4435_3 test_bug33831 test_bug44495 test_bug49972 test_bug42373 test_bug58036 test_bug11766854 test_bug54790 test_bug11754979 test_wl5924 test_wl6587 test_bug17309863 test_bug17512527 test_bug20444737 test_bug21104470 test_bug21293012 test_bug21199582 test_bug20821550 test_wl8754 test_skip_metadata test_wl13510 test_wl13510_multi_statements test_bug32391415 test_wl11381 test_wl11381_qa test_wl11772 test_wl12475 test_wl12542 test_bug32847269 test_wl13075 test_bug34007830 test_wl13128 test_bug25584097 test_34556764 test_bug31048553 test_bug31082201 test_bug31104389 test_bug32892045 test_server_telemetry_traces
./build/bin/mysql_client_test -h 127.0.0.1 -P 6000 -u root -proot -Dclient_test_db test_bug5194 disable_query_logs client_query test_prepare_insert_update test_fetch_seek test_fetch_nobuffs test_open_direct test_fetch_null test_ps_null_param test_fetch_date test_fetch_str test_fetch_long test_fetch_short test_fetch_tiny test_fetch_bigint test_fetch_float test_fetch_double test_bind_result_ext test_bind_result_ext1 test_select_direct test_select_prepare test_select test_select_version test_ps_conj_query_block test_select_show_table test_func_fields test_long_data test_insert test_set_variable test_select_show test_prepare_noparam test_time_zone test_bind_result test_prepare_simple test_prepare test_null test_debug_example test_update test_simple_update test_simple_delete test_double_compare client_store_result client_use_result test_tran_bdb test_tran_innodb test_prepare_ext test_prepare_syntax test_field_names test_field_flags test_bug33781442 test_long_data_str test_long_data_str1 test_long_data_bin test_warnings test_errors test_prepare_resultset test_stmt_close test_prepare_field_result test_multi_stmt test_multi_statements test_prepare_multi_statements test_store_result test_store_result1 test_store_result2 test_subselect test_date test_date_frac test_simple_temporal test_temporal_param test_temporal_functions test_date_date test_date_time test_date_ts test_date_dt test_prepare_alter test_manual_sample test_pure_coverage test_buffers test_ushort_bug test_sshort_bug test_stiny_bug test_field_misc test_set_option test_explain_bug test_decimal_bug test_nstmts "test_logs;" test_truncated_rows test_fetch_offset test_fetch_column test_mem_overun test_list_fields test_free_result test_free_store_result test_sqlmode test_ts test_bug1115 test_bug1180 test_bug1500 test_bug1644 test_bug1946 test_bug2248 test_parse_error_and_bad_length test_bug2247 test_subqueries test_bad_union test_distinct test_subqueries_ref test_union test_bug3117 test_join test_selecttmp test_create_drop test_rename test_do_set test_multi test_insert_select test_bind_nagative test_derived test_xjoin test_bug3035 test_union2 test_bug1664 test_union_param test_order_param test_ps_i18n test_bug3796 test_bug4026 test_bug4079 test_bug4236 test_bug4030 test_bug5126 test_bug4231 test_bug5399 test_bug5194 test_bug6049 test_bug6058 test_bug6059 test_bug6046 test_bug6081 test_bug6096 test_datetime_ranges test_bug4172 test_conversion test_rewind test_bug6761 test_view test_view_where test_view_2where test_view_star test_view_insert test_left_join_view test_view_insert_fields test_basic_cursors test_cursors_with_union test_cursor_for_show test_truncation test_truncation_option test_client_character_set test_bug8330 test_bug7990 test_bug8378 test_bug8722 test_bug8880 test_bug9159 test_bug9520 test_bug9478 test_bug9643 test_bug10729 test_bug11111 test_bug9992 test_bug10736 test_bug10794 test_bug11172 test_bug11656 test_bug10214 test_bug21246 test_bug9735 test_bug11183 test_bug11037 test_bug10760 test_bug12001 test_bug11718 test_bug12925 test_bug11909 test_bug11901 test_bug11904 test_bug12243 test_bug14210 test_bug13488 test_bug13524 test_bug14845 test_opt_reconnect test_bug15510 test_bug12744 test_bug16143 test_bug16144 test_bug15613 test_bug20152 test_bug17667 test_bug15752 test_mysql_insert_id test_bug19671 test_bug21206 test_bug21726 test_bug15518 test_bug23383 test_bug32265 test_bug21635 test_status test_bug24179 test_bug28075 test_bug27876 test_bug28505 test_bug28934 test_bug27592 test_bug29687 test_bug29692 test_bug29306 test_bug45010 test_bug28386 test_wl4166_1 test_wl4166_2 test_wl4166_3 test_wl4166_4 test_bug36004 test_wl4284_1 test_bug38486 test_bug40365 test_bug43560 test_bug36326 test_bug41078 test_bug54041 test_bug47485 test_bug57058 test_bug56976 test_bug12337762 test_bug13001491 test_wl5968 test_wl5928 test_wl6797 test_wl6791 test_wl5768 test_wl8016 test_bug20645725 test_bug19894382 test_bug17883203 test_bug22336527 test_bug24963580 test_mysql_binlog test_bug22028117 test_bug25701141 test_bug27443252 test_limit_syntax test_param_integer test_bug30032302 test_wl13168 test_wl13905 test_bug31691060_1 test_bug31691060_2 test_bug32372038 test_bug32558782 test_bug33164347 test_bug32915973 test_bug33535746 test_bug34869076
- name: "set up tmate session if necessary"
if: ${{ failure() && inputs.debug }}
uses: mxschmitt/action-tmate@v3
8 changes: 8 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ jobs:
target: "test"
all_platform: false

it:
if: ${{ github.event_name != 'push' }}
needs: cmd
uses: ./.github/workflows/integration.yml
with:
debug: ${{ github.event_name == 'workflow_dispatch' && inputs.debug }}
ref: ${{ inputs.ref || github.ref }}

cache:
if: ${{ github.event_name == 'push' }}
uses: ./.github/workflows/common.yml
Expand Down
7 changes: 1 addition & 6 deletions conf/proxy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,7 @@
# server object
[security.server-tls]
# proxy SQL or HTTP port will use this
# auto-certs: true

# peer object
[security.peer-tls]
# internal communication between proxies
# auto-certs: true
# auto-certs = true

[metrics]

Expand Down
3 changes: 2 additions & 1 deletion pkg/manager/namespace/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package namespace
import (
"fmt"
"net/http"
"reflect"
"sync"

"github.com/pingcap/TiProxy/lib/config"
Expand All @@ -33,7 +34,7 @@ func (mgr *NamespaceManager) buildNamespace(cfg *config.Namespace) (*Namespace,
logger := mgr.logger.With(zap.String("namespace", cfg.Namespace))

var fetcher router.BackendFetcher
if mgr.tpFetcher != nil {
if !reflect.ValueOf(mgr.tpFetcher).IsNil() {
fetcher = router.NewPDFetcher(mgr.tpFetcher, logger.Named("be_fetcher"), config.NewDefaultHealthCheckConfig())
} else {
fetcher = router.NewStaticFetcher(cfg.Backend.Instances)
Expand Down
9 changes: 9 additions & 0 deletions pkg/proxy/backend/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package backend

import (
"bytes"
"crypto/tls"
"encoding/binary"
"fmt"
Expand Down Expand Up @@ -209,6 +210,8 @@ func (auth *Authenticator) handshakeFirstTime(logger *zap.Logger, cctx ConnConte
}

// forward other packets
pluginName := ""
loop:
for {
serverPkt, err := forwardMsg(backendIO, clientIO)
if err != nil {
Expand All @@ -220,6 +223,12 @@ func (auth *Authenticator) handshakeFirstTime(logger *zap.Logger, cctx ConnConte
case mysql.ErrHeader:
return pnet.ParseErrorPacket(serverPkt)
default: // mysql.AuthSwitchRequest, ShaCommand
if serverPkt[0] == mysql.AuthSwitchRequest {
pluginName = string(serverPkt[1 : bytes.IndexByte(serverPkt[1:], 0)+1])
} else if serverPkt[0] == 1 && pluginName == mysql.AuthCachingSha2Password && len(serverPkt) == 2 && serverPkt[1] == 3 {
// caching_sha2_password fast path
continue loop
}
if _, err = forwardMsg(clientIO, backendIO); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/proxy/backend/backend_conn_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func (mgr *BackendConnManager) ExecuteCmd(ctx context.Context, request []byte) (
if !IsMySQLError(err) {
return
} else {
mgr.logger.Debug("got a mysql error", zap.Error(err))
mgr.logger.Debug("got a mysql error", zap.Error(err), zap.Stringer("cmd", cmd))
}
}
if err == nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func NewServer(ctx context.Context, sctx *sctx.Context) (srv *Server, err error)
}

// setup info syncer
{
if cfg.Proxy.PDAddrs != "" {
srv.InfoSyncer = infosync.NewInfoSyncer(lg.Named("infosync"))
if err = srv.InfoSyncer.Init(ctx, cfg, srv.CertManager); err != nil {
return
Expand Down

0 comments on commit 0c03603

Please sign in to comment.