-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connectors flaky tests fix #1717
base: main
Are you sure you want to change the base?
Changes from all commits
d323882
c723618
6749619
29532fe
f8d3043
1e04508
ce19fd9
006b3f2
9153ed8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -396,11 +396,20 @@ func (k *connectorClusterService) GetClientID(clusterID string) (string, error) | |
// SaveDeployment creates a connector deployment in the database | ||
func (k *connectorClusterService) SaveDeployment(ctx context.Context, resource *dbapi.ConnectorDeployment) *errors.ServiceError { | ||
dbConn := k.connectionFactory.New() | ||
if resource.Version != 0 { | ||
dbConn = dbConn.Where("version = ?", resource.Version) | ||
} | ||
|
||
if err := dbConn.Save(resource).Error; err != nil { | ||
saveResult := dbConn.Save(resource) | ||
if err := saveResult.Error; err != nil { | ||
return services.HandleCreateError(`Connector deployment`, err) | ||
} | ||
if saveResult.RowsAffected == 0 { | ||
return errors.Conflict("Optimistic locking: resource version changed from %v", resource.Version) | ||
} | ||
|
||
//refresh version | ||
dbConn = k.connectionFactory.New() | ||
if err := dbConn.Where("id = ?", resource.ID).Select("version").First(&resource).Error; err != nil { | ||
return services.HandleGetError(`Connector deployment`, "id", resource.ID, err) | ||
} | ||
|
@@ -416,11 +425,20 @@ func (k *connectorClusterService) SaveDeployment(ctx context.Context, resource * | |
|
||
func (k *connectorClusterService) UpdateDeployment(resource *dbapi.ConnectorDeployment) *errors.ServiceError { | ||
dbConn := k.connectionFactory.New() | ||
|
||
if resource.Version != 0 { | ||
dbConn = dbConn.Where("version = ?", resource.Version) | ||
} | ||
|
||
updates := dbConn.Where("id = ?", resource.ID). | ||
Updates(resource) | ||
if err := updates.Error; err != nil { | ||
return services.HandleUpdateError(`Connector namespace`, err) | ||
return services.HandleUpdateError(`Connector deployment`, err) | ||
} | ||
if updates.RowsAffected == 0 { | ||
return errors.Conflict("Optimistic locking: resource version changed from %v", resource.Version) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
@@ -494,7 +512,7 @@ func (k *connectorClusterService) ListConnectorDeployments(ctx context.Context, | |
func (k *connectorClusterService) UpdateConnectorDeploymentStatus(ctx context.Context, deploymentStatus dbapi.ConnectorDeploymentStatus) *errors.ServiceError { | ||
dbConn := k.connectionFactory.New() | ||
|
||
// lets get the connector id of the deployment.. | ||
// let's get the connector id of the deployment... | ||
deployment := dbapi.ConnectorDeployment{} | ||
if err := dbConn.Unscoped().Select("connector_id", "deleted_at"). | ||
Where("id = ?", deploymentStatus.ID). | ||
|
@@ -505,7 +523,7 @@ func (k *connectorClusterService) UpdateConnectorDeploymentStatus(ctx context.Co | |
return services.HandleGoneError("Connector deployment", "id", deploymentStatus.ID) | ||
} | ||
|
||
if err := dbConn.Model(&deploymentStatus).Where("id = ? and version <= ?", deploymentStatus.ID, deploymentStatus.Version).Save(&deploymentStatus).Error; err != nil { | ||
if err := dbConn.Where("id = ? and version <= ?", deploymentStatus.ID, deploymentStatus.Version).Save(&deploymentStatus).Error; err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I just removed the use of So I believe we can merge this one and then reason about the whole |
||
return errors.Conflict("failed to update deployment status: %s, probably a stale deployment status version was used: %d", err.Error(), deploymentStatus.Version) | ||
} | ||
|
||
|
@@ -531,8 +549,8 @@ func (k *connectorClusterService) UpdateConnectorDeploymentStatus(ctx context.Co | |
} | ||
} | ||
|
||
// update the connector status | ||
if err := dbConn.Where("id = ?", deployment.ConnectorID).Updates(&connectorStatus).Error; err != nil { | ||
// update the connector status, don't updated deleted statues | ||
if err := dbConn.Where("deleted_at IS NULL AND id = ?", deployment.ConnectorID).Updates(&connectorStatus).Error; err != nil { | ||
return services.HandleUpdateError("Connector status", err) | ||
} | ||
|
||
|
@@ -564,7 +582,7 @@ func (k *connectorClusterService) FindAvailableNamespace(owner string, orgID str | |
|
||
func (k *connectorClusterService) GetDeploymentByConnectorId(ctx context.Context, connectorID string) (resource dbapi.ConnectorDeployment, serr *errors.ServiceError) { | ||
|
||
if err := k.connectionFactory.New().Preload(clause.Associations). | ||
if err := k.connectionFactory.New(). | ||
Joins("Status").Joins("ConnectorShardMetadata").Joins("Connector"). | ||
Where("connector_id = ?", connectorID).First(&resource).Error; err != nil { | ||
return resource, services.HandleGetError("Connector deployment", "connector_id", connectorID, err) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I worry about this.
See https://github.com/bf2fc6cc711aee1a0c2a/kas-fleet-manager/pull/1637/files#diff-aee57c287964506015af5e0e2839d1e78a19635c9ce232369e8be08a91101d89R508-R517
The behaviour of
Save
has changed in newer versions ofgorm
.I believe PR #1717 and #1637 are effectively in a "race condition".
We should agree which should merge first and then check the other is unaffected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As stated in the more general comment I would vote for merging this one since it fixes tests and current behavior and then reason about how to deal with new gorm version behavior.