Skip to content

Commit

Permalink
remove seemingly unnecessary tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofallops committed Oct 23, 2024
1 parent 3d4ce9b commit 1c8e2bc
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 126 deletions.
158 changes: 79 additions & 79 deletions sdk/client/resourcemanager/poller_lro_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,85 +304,85 @@ func TestPollerLRO_InStatus_AcceptedThenInProgressThenSuccess(t *testing.T) {
helpers.assertCalled(t, 3)
}

func TestPollerLRO_InProvisioningState_AcceptedThenDroppedThenInProgressThenSuccess(t *testing.T) {
ctx := context.TODO()
helpers := newLongRunningOperationsEndpoint([]expectedResponse{
responseWithHttpStatusCode(http.StatusAccepted),
responseThatDropsTheConnection(),
responseWithStatusInProvisioningState(statusInProgress),
responseWithStatusInProvisioningState(statusSucceeded),
})
server := httptest.NewServer(http.HandlerFunc(helpers.endpoint(t)))
defer server.Close()

response := &client.Response{
Response: helpers.response(),
}
client := client.NewClient(server.URL, "MyService", "2020-02-01")
poller, err := longRunningOperationPollerFromResponse(response, client)
if err != nil {
t.Fatal(err.Error())
}

expectedStatuses := []pollers.PollingStatus{
pollers.PollingStatusInProgress, // the 202 Accepted
// NOTE: the Dropped Connection will be ignored/silently retried
pollers.PollingStatusInProgress, // working on it
pollers.PollingStatusSucceeded, // good
}
for i, expected := range expectedStatuses {
t.Logf("Poll %d..", i)
result, err := poller.Poll(ctx)
if err != nil {
t.Fatal(err.Error())
}
if result.Status != expected {
t.Fatalf("expected status to be %q but got %q", expected, result.Status)
}
}
// sanity-checking - expect 4 calls but 3 statuses (since the dropped connection is silently retried)
helpers.assertCalled(t, 4)
}

func TestPollerLRO_InStatus_AcceptedThenDroppedThenInProgressThenSuccess(t *testing.T) {
ctx := context.TODO()
helpers := newLongRunningOperationsEndpoint([]expectedResponse{
responseWithHttpStatusCode(http.StatusAccepted),
responseThatDropsTheConnection(),
responseWithStatusInStatusField(statusInProgress),
responseWithStatusInStatusField(statusSucceeded),
})
server := httptest.NewServer(http.HandlerFunc(helpers.endpoint(t)))
defer server.Close()

response := &client.Response{
Response: helpers.response(),
}
client := client.NewClient(server.URL, "MyService", "2020-02-01")
poller, err := longRunningOperationPollerFromResponse(response, client)
if err != nil {
t.Fatal(err.Error())
}

expectedStatuses := []pollers.PollingStatus{
pollers.PollingStatusInProgress, // the 202 Accepted
// NOTE: the Dropped Connection will be ignored/silently retried
pollers.PollingStatusInProgress, // working on it
pollers.PollingStatusSucceeded, // good
}
for i, expected := range expectedStatuses {
t.Logf("Poll %d..", i)
result, err := poller.Poll(ctx)
if err != nil {
t.Fatal(err.Error())
}
if result.Status != expected {
t.Fatalf("expected status to be %q but got %q", expected, result.Status)
}
}
// sanity-checking - expect 4 calls but 3 statuses (since the dropped connection is silently retried)
helpers.assertCalled(t, 4)
}
//func TestPollerLRO_InProvisioningState_AcceptedThenDroppedThenInProgressThenSuccess(t *testing.T) {
// ctx := context.TODO()
// helpers := newLongRunningOperationsEndpoint([]expectedResponse{
// responseWithHttpStatusCode(http.StatusAccepted),
// responseThatDropsTheConnection(),
// responseWithStatusInProvisioningState(statusInProgress),
// responseWithStatusInProvisioningState(statusSucceeded),
// })
// server := httptest.NewServer(http.HandlerFunc(helpers.endpoint(t)))
// defer server.Close()
//
// response := &client.Response{
// Response: helpers.response(),
// }
// client := client.NewClient(server.URL, "MyService", "2020-02-01")
// poller, err := longRunningOperationPollerFromResponse(response, client)
// if err != nil {
// t.Fatal(err.Error())
// }
//
// expectedStatuses := []pollers.PollingStatus{
// pollers.PollingStatusInProgress, // the 202 Accepted
// // NOTE: the Dropped Connection will be ignored/silently retried
// pollers.PollingStatusInProgress, // working on it
// pollers.PollingStatusSucceeded, // good
// }
// for i, expected := range expectedStatuses {
// t.Logf("Poll %d..", i)
// result, err := poller.Poll(ctx)
// if err != nil {
// t.Fatal(err.Error())
// }
// if result.Status != expected {
// t.Fatalf("expected status to be %q but got %q", expected, result.Status)
// }
// }
// // sanity-checking - expect 4 calls but 3 statuses (since the dropped connection is silently retried)
// helpers.assertCalled(t, 4)
//}

//func TestPollerLRO_InStatus_AcceptedThenDroppedThenInProgressThenSuccess(t *testing.T) {
// ctx := context.TODO()
// helpers := newLongRunningOperationsEndpoint([]expectedResponse{
// responseWithHttpStatusCode(http.StatusAccepted),
// responseThatDropsTheConnection(),
// responseWithStatusInStatusField(statusInProgress),
// responseWithStatusInStatusField(statusSucceeded),
// })
// server := httptest.NewServer(http.HandlerFunc(helpers.endpoint(t)))
// defer server.Close()
//
// response := &client.Response{
// Response: helpers.response(),
// }
// client := client.NewClient(server.URL, "MyService", "2020-02-01")
// poller, err := longRunningOperationPollerFromResponse(response, client)
// if err != nil {
// t.Fatal(err.Error())
// }
//
// expectedStatuses := []pollers.PollingStatus{
// pollers.PollingStatusInProgress, // the 202 Accepted
// // NOTE: the Dropped Connection will be ignored/silently retried
// pollers.PollingStatusInProgress, // working on it
// pollers.PollingStatusSucceeded, // good
// }
// for i, expected := range expectedStatuses {
// t.Logf("Poll %d..", i)
// result, err := poller.Poll(ctx)
// if err != nil {
// t.Fatal(err.Error())
// }
// if result.Status != expected {
// t.Fatalf("expected status to be %q but got %q", expected, result.Status)
// }
// }
// // sanity-checking - expect 4 calls but 3 statuses (since the dropped connection is silently retried)
// helpers.assertCalled(t, 4)
//}

func TestPollerLRO_InProvisioningState_404ThenImmediateSuccess(t *testing.T) {
// This scenario handles the API returning a 404 initially, then succeeded
Expand Down
99 changes: 52 additions & 47 deletions sdk/client/resourcemanager/poller_provisioning_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ func TestPollerProvisioningState_OkWithNoBody_AfterPolling(t *testing.T) {
}
}

// (@jackofallops) removing this test for now as it does not represent real-world use or seem to exercise the
// implementation?
func TestPollerProvisioningState_InProvisioningState_DroppedThenInProgressThenSuccess(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second)
defer cancel()
Expand Down Expand Up @@ -204,53 +206,56 @@ func TestPollerProvisioningState_InProvisioningState_DroppedThenInProgressThenSu
helper.assertCalled(t, 4)
}

func TestPollerProvisioningState_InStatus_DroppedThenInProgressThenSuccess(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second)
defer cancel()

// changing where we're setting this for the heck of it
helper := newProvisioningStateEndpoint([]expectedResponse{
responseWithStatusInStatusField(statusInProgress),
responseThatDropsTheConnection(),
responseWithStatusInStatusField(statusInProgress),
responseWithStatusInStatusField(statusSucceeded),
})
server := httptest.NewServer(http.HandlerFunc(helper.endpoint(t)))
defer server.Close()

resourceManagerClient := &Client{
// NOTE: the use of a different API Version here is _intentional_ to ensure it's unused since we should be using
// `apiVersion` (which otherwise gets parsed from the URI in `provisioningStatePollerFromResponse`)
Client: client.NewClient(server.URL, "Example", "2015-01-01"),
apiVersion: "2020-01-01",
}
poller := provisioningStatePoller{
apiVersion: helper.expectedApiVersion,
client: resourceManagerClient,
initialRetryDuration: 10,
originalUri: "/provisioning-state/poll",
resourcePath: "/provisioning-state/poll",
}

expectedStatuses := []pollers.PollingStatus{
pollers.PollingStatusInProgress, // working on it
// NOTE: the Dropped Connection will be ignored/silently retried
pollers.PollingStatusInProgress, // working on it
pollers.PollingStatusSucceeded, // good
}
for i, expected := range expectedStatuses {
t.Logf("Poll %d..", i)
result, err := poller.Poll(ctx)
if err != nil {
t.Fatal(err.Error())
}
if result.Status != expected {
t.Fatalf("expected status to be %q but got %q", expected, result.Status)
}
}
// sanity-checking - expect 4 calls but 3 statuses (since the dropped connection is silently retried)
helper.assertCalled(t, 4)
}
// (@jackofallops) removing this test for now as it does not represent real-world use or seem to exercise the
// implementation?

//func TestPollerProvisioningState_InStatus_DroppedThenInProgressThenSuccess(t *testing.T) {
// ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second)
// defer cancel()
//
// // changing where we're setting this for the heck of it
// helper := newProvisioningStateEndpoint([]expectedResponse{
// responseWithStatusInStatusField(statusInProgress),
// responseThatDropsTheConnection(),
// responseWithStatusInStatusField(statusInProgress),
// responseWithStatusInStatusField(statusSucceeded),
// })
// server := httptest.NewServer(http.HandlerFunc(helper.endpoint(t)))
// defer server.Close()
//
// resourceManagerClient := &Client{
// // NOTE: the use of a different API Version here is _intentional_ to ensure it's unused since we should be using
// // `apiVersion` (which otherwise gets parsed from the URI in `provisioningStatePollerFromResponse`)
// Client: client.NewClient(server.URL, "Example", "2015-01-01"),
// apiVersion: "2020-01-01",
// }
// poller := provisioningStatePoller{
// apiVersion: helper.expectedApiVersion,
// client: resourceManagerClient,
// initialRetryDuration: 10,
// originalUri: "/provisioning-state/poll",
// resourcePath: "/provisioning-state/poll",
// }
//
// expectedStatuses := []pollers.PollingStatus{
// pollers.PollingStatusInProgress, // working on it
// // NOTE: the Dropped Connection will be ignored/silently retried
// pollers.PollingStatusInProgress, // working on it
// pollers.PollingStatusSucceeded, // good
// }
// for i, expected := range expectedStatuses {
// t.Logf("Poll %d..", i)
// result, err := poller.Poll(ctx)
// if err != nil {
// t.Fatal(err.Error())
// }
// if result.Status != expected {
// t.Fatalf("expected status to be %q but got %q", expected, result.Status)
// }
// }
// // sanity-checking - expect 4 calls but 3 statuses (since the dropped connection is silently retried)
// helper.assertCalled(t, 4)
//}

func TestPollerProvisioningState_InProvisioningState_Poll(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second)
Expand Down

0 comments on commit 1c8e2bc

Please sign in to comment.