trafficcontrol-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mitchell...@apache.org
Subject [trafficcontrol] branch master updated: Fix bug that causes DS requests to fulfill immediately while other requests are still open (#3727)
Date Wed, 24 Jul 2019 14:28:48 GMT
This is an automated email from the ASF dual-hosted git repository.

mitchell852 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 1d2bc4a  Fix bug that causes DS requests to fulfill immediately while other requests
are still open (#3727)
1d2bc4a is described below

commit 1d2bc4affe4cac2c7f60d0e6add91867669ab3a6
Author: Alex Luckerman <35511862+alexluckerman@users.noreply.github.com>
AuthorDate: Wed Jul 24 08:28:41 2019 -0600

    Fix bug that causes DS requests to fulfill immediately while other requests are still
open (#3727)
    
    * Prevent DS changes while other requests are open
    
    * Add sleep to fix DS requests test failing too fast
    
    * Simplify the check for existing DS requests
    
    * Fix comments describing code logic
---
 .../edit/FormEditDeliveryServiceController.js      | 104 ++++++++++-----------
 .../delivery-service-requests-spec.js              |   1 +
 2 files changed, 50 insertions(+), 55 deletions(-)

diff --git a/traffic_portal/app/src/common/modules/form/deliveryService/edit/FormEditDeliveryServiceController.js
b/traffic_portal/app/src/common/modules/form/deliveryService/edit/FormEditDeliveryServiceController.js
index 9f6f340..e6d297e 100644
--- a/traffic_portal/app/src/common/modules/form/deliveryService/edit/FormEditDeliveryServiceController.js
+++ b/traffic_portal/app/src/common/modules/form/deliveryService/edit/FormEditDeliveryServiceController.js
@@ -59,46 +59,42 @@ var FormEditDeliveryServiceController = function(deliveryService, origin,
type,
 				deliveryService: deliveryService
 			};
 
-			// if the user chooses to complete/fulfill the delete request immediately, the ds will
be deleted and behind the
-			// scenes a delivery service request will be created and marked as complete
-			if (options.status.id == $scope.COMPLETE) {
-				// first delete the ds
-				deliveryServiceService.deleteDeliveryService(deliveryService)
-					.then(
-						function() {
-							// then create the ds request
-							deliveryServiceRequestService.createDeliveryServiceRequest(dsRequest).
-								then(
-									function(response) {
-										var comment = {
-											deliveryServiceRequestId: response.id,
-											value: options.comment
-										};
-										// then create the ds request comment
-										deliveryServiceRequestService.createDeliveryServiceRequestComment(comment).
-											then(
-												function() {
-													var promises = [];
-													// assign the ds request
-													promises.push(deliveryServiceRequestService.assignDeliveryServiceRequest(response.id,
userModel.user.id));
-													// set the status to 'complete'
-													promises.push(deliveryServiceRequestService.updateDeliveryServiceRequestStatus(response.id,
'complete'));
-													// and finally navigate to the /delivery-services page
-													messageModel.setMessages([ { level: 'success', text: 'Delivery service [ ' +
deliveryService.xmlId + ' ] deleted' } ], true);
-													locationUtils.navigateToPath('/delivery-services');
-												}
-											);
-									}
-								);
-						},
-						function(fault) {
-							$anchorScroll(); // scrolls window to top
-							messageModel.setMessages(fault.data.alerts, false);
-						}
-					);
-
-
-
+			// if the user chooses to complete/fulfill the delete request immediately, a delivery
service request will be made and marked as complete, 
+			// then if that is successful, the DS will be deleted
+			if (options.status.id === $scope.COMPLETE) {
+				// first create the ds request
+				deliveryServiceRequestService.createDeliveryServiceRequest(dsRequest)
+					.then(function(response) {
+						var comment = {
+							deliveryServiceRequestId: response.id,
+							value: options.comment
+						};
+						// then create the ds request comment
+						deliveryServiceRequestService.createDeliveryServiceRequestComment(comment).
+							then(
+								function() {
+									var promises = [];
+									// assign the ds request
+									promises.push(deliveryServiceRequestService.assignDeliveryServiceRequest(response.id,
userModel.user.id));
+									// set the status to 'complete'
+									promises.push(deliveryServiceRequestService.updateDeliveryServiceRequestStatus(response.id,
'complete'));
+									// and finally navigate to the /delivery-services page
+									messageModel.setMessages([ { level: 'success', text: 'Delivery service [ ' + deliveryService.xmlId
+ ' ] deleted' } ], true);
+									locationUtils.navigateToPath('/delivery-services');
+								}
+							// then, if all that works, delete the ds	
+							).then(
+								function() {
+									deliveryServiceService.deleteDeliveryService(deliveryService);
+								}
+							);
+					}
+					// handle any failures just once
+					).catch(function(fault) {
+						$anchorScroll(); // scrolls window to top
+						messageModel.setMessages(fault.data.alerts, false);
+					}
+				);
 			} else {
 				deliveryServiceRequestService.createDeliveryServiceRequest(dsRequest).
 					then(
@@ -123,7 +119,7 @@ var FormEditDeliveryServiceController = function(deliveryService, origin,
type,
 	};
 
 	var createDeliveryServiceUpdateRequest = function(dsRequest, dsRequestComment, autoFulfilled)
{
-		deliveryServiceRequestService.createDeliveryServiceRequest(dsRequest).
+		return deliveryServiceRequestService.createDeliveryServiceRequest(dsRequest).
 			then(
 				function(response) {
 					var comment = {
@@ -198,21 +194,19 @@ var FormEditDeliveryServiceController = function(deliveryService, origin,
type,
 					status: status,
 					deliveryService: deliveryService
 				};
-				// if the user chooses to complete/fulfill the update request immediately, the ds will
be updated and behind the
-				// scenes a delivery service request will be created and marked as complete
+				// if the user chooses to complete/fulfill the update request immediately, a delivery
service request will be made and marked as complete, 
+				// then if that is successful, the DS will be updated
 				if (options.status.id == $scope.COMPLETE) {
-					deliveryServiceService.updateDeliveryService(deliveryService).
-						then(
-							function() {
-								$state.reload(); // reloads all the resolves for the view
-								messageModel.setMessages([ { level: 'success', text: 'Delivery Service [ ' + deliveryService.xmlId
+ ' ] updated' } ], false);
-								createDeliveryServiceUpdateRequest(dsRequest, options.comment, true);
-							},
-							function(fault) {
-								$anchorScroll(); // scrolls window to top
-								messageModel.setMessages(fault.data.alerts, false);
-							}
-						);
+					createDeliveryServiceUpdateRequest(dsRequest, options.comment, true).then(
+						function() {
+							deliveryServiceService.updateDeliveryService(deliveryService);
+						}).then(function() {
+							$state.reload(); // reloads all the resolves for the view
+							messageModel.setMessages([ { level: 'success', text: 'Delivery Service [ ' + deliveryService.xmlId
+ ' ] updated' } ], false);
+						}).catch(function(fault) {
+							$anchorScroll(); // scrolls window to top
+							messageModel.setMessages(fault.data.alerts, false);
+					});
 				} else {
 					createDeliveryServiceUpdateRequest(dsRequest, options.comment, false);
 				}
diff --git a/traffic_portal/test/end_to_end/DeliveryServiceRequests/delivery-service-requests-spec.js
b/traffic_portal/test/end_to_end/DeliveryServiceRequests/delivery-service-requests-spec.js
index a9fb161..2b4d57c 100644
--- a/traffic_portal/test/end_to_end/DeliveryServiceRequests/delivery-service-requests-spec.js
+++ b/traffic_portal/test/end_to_end/DeliveryServiceRequests/delivery-service-requests-spec.js
@@ -144,6 +144,7 @@ describe('Traffic Portal Delivery Service Requests', function() {
 		pageData.deleteButton.click();
 		pageData.confirmWithNameInput.sendKeys(mockVals.xmlId + ' request');
 		pageData.deletePermanentlyButton.click();
+		browser.sleep(250);
 		expect(browser.getCurrentUrl().then(commonFunctions.urlPath)).toEqual(commonFunctions.urlPath(browser.baseUrl)+"#!/delivery-service-requests");
 	});
 });


Mime
View raw message