Copilot commented on code in PR #1119: URL: https://github.com/apache/incubator-seata-go/pull/1119#discussion_r3292523794
########## pkg/datasource/sql/oracle_xa_integration_test.go: ########## @@ -0,0 +1,291 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 sql + +import ( + "context" + "database/sql" + "fmt" + "os" + "sync" + "sync/atomic" + "testing" + "time" + + "github.com/bluele/gcache" + "github.com/stretchr/testify/require" + + "seata.apache.org/seata-go/v2/pkg/datasource/sql/datasource" + "seata.apache.org/seata-go/v2/pkg/datasource/sql/types" + "seata.apache.org/seata-go/v2/pkg/protocol/branch" + "seata.apache.org/seata-go/v2/pkg/rm" + "seata.apache.org/seata-go/v2/pkg/tm" +) + +type oracleXAIntegrationManager struct { + resources sync.Map + nextID int64 + lastID int64 + reports []rm.BranchReportParam +} + +func (m *oracleXAIntegrationManager) BranchCommit(context.Context, rm.BranchResource) (branch.BranchStatus, error) { + return branch.BranchStatusPhasetwoCommitted, nil +} + +func (m *oracleXAIntegrationManager) BranchRollback(context.Context, rm.BranchResource) (branch.BranchStatus, error) { + return branch.BranchStatusPhasetwoRollbacked, nil +} + +func (m *oracleXAIntegrationManager) BranchRegister(_ context.Context, _ rm.BranchRegisterParam) (int64, error) { + id := atomic.AddInt64(&m.nextID, 1) + m.lastID = id + return id, nil +} + +func (m *oracleXAIntegrationManager) BranchReport(_ context.Context, param rm.BranchReportParam) error { + m.reports = append(m.reports, param) + return nil +} + +func (m *oracleXAIntegrationManager) LockQuery(context.Context, rm.LockQueryParam) (bool, error) { + return true, nil +} + +func (m *oracleXAIntegrationManager) RegisterResource(resource rm.Resource) error { + m.resources.Store(resource.GetResourceId(), resource) + return nil +} + +func (m *oracleXAIntegrationManager) UnregisterResource(rm.Resource) error { + return nil +} + +func (m *oracleXAIntegrationManager) GetCachedResources() *sync.Map { + return &m.resources +} + +func (m *oracleXAIntegrationManager) GetBranchType() branch.BranchType { + return branch.BranchTypeXA +} + +func (m *oracleXAIntegrationManager) CreateTableMetaCache(context.Context, string, types.DBType, *sql.DB) (datasource.TableMetaCache, error) { + return nil, nil +} + +func TestOracleXAIntegration_SeataXAOracleFirstAndSecondPhase(t *testing.T) { + dsn := os.Getenv("ORACLE_XA_DSN") + if dsn == "" { + t.Skip("set ORACLE_XA_DSN to run Oracle XA integration test") + } + + branchStatusCache = gcache.New(1024).LRU().Expiration(time.Minute * 10).Build() + xaConnTimeout = time.Hour + t.Cleanup(func() { + xaConnTimeout = 0 + }) + + ctx := context.Background() + manager := &oracleXAIntegrationManager{} + rm.GetRmCacheInstance().RegisterResourceManager(manager) Review Comment: This test mutates global state (branchStatusCache, XA RM registration) but the cleanup only resets xaConnTimeout. If this integration test runs (when ORACLE_XA_DSN is set), it can leak global state into subsequent tests and cause order-dependent failures. Add cleanup to restore branchStatusCache (e.g., set it to nil) and unregister/restore the previous XA ResourceManager (or use registerResourceManagerForTest which already handles cleanup). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
