Skip to content
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

Add delete_after_n method to When #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wfchandler
Copy link

In situations where a component is expected to automatically retry an endpoint, manually calling delete on a Mock may not be an option.

To support this scenario, add a new delete_after_n method to When that will remove the Mock from the server after it has matched the specified number of calls.

Related to #76
Related to #96

In situations where a component is expected to automatically retry an
endpoint manually calling `delete` on a `Mock` may not be an option.

To support this scenario, add a new `delete_after_n` method to `When`
that will remove the `Mock` from the server after it has matched the
specified number of calls.

Related to alexliesenfeld#76
Related to alexliesenfeld#96
@alexliesenfeld
Copy link
Owner

alexliesenfeld commented Jul 25, 2024

Thank you for your PR @wfchandler! Looks like a useful addition. I will have a closer look at it or get back to you soon!

wfchandler added a commit to oxidecomputer/oxide.rs that referenced this pull request Sep 16, 2024
From a user perspective uploading a disk is a single operation, but
doing so via the SDK is a very involved process, involving stringing
together multiple API calls with any interruption leaving the disk in a
state that cannot be directly removed.

Add a new `extras` module to the SDK that will contain convenience
wrappers around actions that functions that are overly complicated.
Create a `disk_import` function in `extras` that will perform a disk
upload as a single step, and attempts to cleanup partially imported
disks on failure. We make the `disk upload` CLI command a thin wrapper
around the new SDK function, responsible only for cancellation and
progress. We manually recreate the builder interface, as creating a
procmacro to do this would require creating a new crate. If/when
`extras` continues to grow we should reconsider this.

`disk_import` also give callers access to a `DiskImportHandle` with a
`watch` channel with the current number of bytes uploaded for use in
progress tracking, and provides a `cancel` function that allows users
to gracefully stop the disk upload. A disk that has been successfully
created will not be removed, only those that are partially imported.

The `cancel` function uses `tokio::select` to cancel the `Future` of
the upload task. This should be safe in our in our case no locks are
held across `await` points. No operations need to be safe to restart as
we only call `tokio::select` a single time, they will be dropped
immediately and losing a message is not a problem.

We are forced to remove tests `test_disk_import_bulk_import_start_fail`
and `test_disk_import_bulk_write_import_fail` as we now poll for disks
in `Created` state, which may happen if a user immediately cancels a new
request. This state is not eligible to be finalized, so we need to wait
for the disk to progress to the next state, but `HttpMock` does not
provide a way to programatically delete or update a mock after sending
`n` responses. This means that the disk will always be returned as
non-existing when querying, and cleanup will be skipped. I have opened
alexliesenfeld/httpmock#108 to add a
`delete_after_n` method, but this seems unlikely to be merged. We may
want to consider moving to `wiremock` in the long term, which provides
this functionality.

Co-authored-by: Adam Leventhal <[email protected]>
wfchandler added a commit to oxidecomputer/oxide.rs that referenced this pull request Sep 16, 2024
From a user perspective uploading a disk is a single operation, but
doing so via the SDK is a very involved process, involving stringing
together multiple API calls with any interruption leaving the disk in a
state that cannot be directly removed.

Add a new `extras` module to the SDK that will contain convenience
wrappers around actions that functions that are overly complicated.
Create a `disk_import` function in `extras` that will perform a disk
upload as a single step, and attempts to cleanup partially imported
disks on failure. We make the `disk upload` CLI command a thin wrapper
around the new SDK function, responsible only for cancellation and
progress. We manually recreate the builder interface, as creating a
procmacro to do this would require creating a new crate. If/when
`extras` continues to grow we should reconsider this.

`disk_import` also give callers access to a `DiskImportHandle` with a
`watch` channel with the current number of bytes uploaded for use in
progress tracking, and provides a `cancel` function that allows users
to gracefully stop the disk upload. A disk that has been successfully
created will not be removed, only those that are partially imported.

The `cancel` function uses `tokio::select` to cancel the `Future` of
the upload task. This should be safe in our in our case no locks are
held across `await` points. No operations need to be safe to restart as
we only call `tokio::select` a single time, they will be dropped
immediately and losing a message is not a problem.

We are forced to remove tests `test_disk_import_bulk_import_start_fail`
and `test_disk_import_bulk_write_import_fail` as we now poll for disks
in `Created` state, which may happen if a user immediately cancels a new
request. This state is not eligible to be finalized, so we need to wait
for the disk to progress to the next state, but `HttpMock` does not
provide a way to programatically delete or update a mock after sending
`n` responses. This means that the disk will always be returned as
non-existing when querying, and cleanup will be skipped. I have opened
alexliesenfeld/httpmock#108 to add a
`delete_after_n` method, but this seems unlikely to be merged. We may
want to consider moving to `wiremock` in the long term, which provides
this functionality.

Co-authored-by: Adam Leventhal <[email protected]>
wfchandler added a commit to oxidecomputer/oxide.rs that referenced this pull request Sep 16, 2024
From a user perspective uploading a disk is a single operation, but
doing so via the SDK is a very involved process, involving stringing
together multiple API calls with any interruption leaving the disk in a
state that cannot be directly removed.

Add a new `extras` module to the SDK that will contain convenience
wrappers around actions that functions that are overly complicated.
Create a `disk_import` function in `extras` that will perform a disk
upload as a single step, and attempts to cleanup partially imported
disks on failure. We make the `disk upload` CLI command a thin wrapper
around the new SDK function, responsible only for cancellation and
progress. We manually recreate the builder interface, as creating a
procmacro to do this would require creating a new crate. If/when
`extras` continues to grow we should reconsider this.

`disk_import` also give callers access to a `DiskImportHandle` with a
`watch` channel with the current number of bytes uploaded for use in
progress tracking, and provides a `cancel` function that allows users
to gracefully stop the disk upload. A disk that has been successfully
created will not be removed, only those that are partially imported.

The `cancel` function uses `tokio::select` to cancel the `Future` of
the upload task. This should be safe in our in our case no locks are
held across `await` points. No operations need to be safe to restart as
we only call `tokio::select` a single time, they will be dropped
immediately and losing a message is not a problem.

We are forced to remove tests `test_disk_import_bulk_import_start_fail`
and `test_disk_import_bulk_write_import_fail` as we now poll for disks
in `Created` state, which may happen if a user immediately cancels a new
request. This state is not eligible to be finalized, so we need to wait
for the disk to progress to the next state, but `HttpMock` does not
provide a way to programatically delete or update a mock after sending
`n` responses. This means that the disk will always be returned as
non-existing when querying, and cleanup will be skipped. I have opened
alexliesenfeld/httpmock#108 to add a
`delete_after_n` method, but this seems unlikely to be merged. We may
want to consider moving to `wiremock` in the long term, which provides
this functionality.

Co-authored-by: Adam Leventhal <[email protected]>
wfchandler added a commit to oxidecomputer/oxide.rs that referenced this pull request Sep 23, 2024
From a user perspective uploading a disk is a single operation, but
doing so via the SDK is a very involved process, involving stringing
together multiple API calls with any interruption leaving the disk in a
state that cannot be directly removed.

Add a new `extras` module to the SDK that will contain convenience
wrappers around actions that functions that are overly complicated.
Create a `disk_import` function in `extras` that will perform a disk
upload as a single step, and attempts to cleanup partially imported
disks on failure. We make the `disk upload` CLI command a thin wrapper
around the new SDK function, responsible only for cancellation and
progress. We manually recreate the builder interface, as creating a
procmacro to do this would require creating a new crate. If/when
`extras` continues to grow we should reconsider this.

`disk_import` also give callers access to a `DiskImportHandle` with a
`watch` channel with the current number of bytes uploaded for use in
progress tracking, and provides a `cancel` function that allows users
to gracefully stop the disk upload. A disk that has been successfully
created will not be removed, only those that are partially imported.

The `cancel` function uses `tokio::select` to cancel the `Future` of
the upload task. This should be safe in our in our case no locks are
held across `await` points. No operations need to be safe to restart as
we only call `tokio::select` a single time, they will be dropped
immediately and losing a message is not a problem.

We are forced to remove tests `test_disk_import_bulk_import_start_fail`
and `test_disk_import_bulk_write_import_fail` as we now poll for disks
in `Created` state, which may happen if a user immediately cancels a new
request. This state is not eligible to be finalized, so we need to wait
for the disk to progress to the next state, but `HttpMock` does not
provide a way to programatically delete or update a mock after sending
`n` responses. This means that the disk will always be returned as
non-existing when querying, and cleanup will be skipped. I have opened
alexliesenfeld/httpmock#108 to add a
`delete_after_n` method, but this seems unlikely to be merged. We may
want to consider moving to `wiremock` in the long term, which provides
this functionality.

Co-authored-by: Adam Leventhal <[email protected]>
wfchandler added a commit to oxidecomputer/oxide.rs that referenced this pull request Sep 23, 2024
From a user perspective uploading a disk is a single operation, but
doing so via the SDK is a very involved process, involving stringing
together multiple API calls with any interruption leaving the disk in a
state that cannot be directly removed.

Add a new `extras` module to the SDK that will contain convenience
wrappers around actions that functions that are overly complicated.
Create a `disk_import` function in `extras` that will perform a disk
upload as a single step, and attempts to cleanup partially imported
disks on failure. We make the `disk upload` CLI command a thin wrapper
around the new SDK function, responsible only for cancellation and
progress. We manually recreate the builder interface, as creating a
procmacro to do this would require creating a new crate. If/when
`extras` continues to grow we should reconsider this.

`disk_import` also give callers access to a `DiskImportHandle` with a
`watch` channel with the current number of bytes uploaded for use in
progress tracking, and provides a `cancel` function that allows users
to gracefully stop the disk upload. A disk that has been successfully
created will not be removed, only those that are partially imported.

The `cancel` function uses `tokio::select` to cancel the `Future` of
the upload task. This should be safe in our in our case no locks are
held across `await` points. No operations need to be safe to restart as
we only call `tokio::select` a single time, they will be dropped
immediately and losing a message is not a problem.

We are forced to remove tests `test_disk_import_bulk_import_start_fail`
and `test_disk_import_bulk_write_import_fail` as we now poll for disks
in `Created` state, which may happen if a user immediately cancels a new
request. This state is not eligible to be finalized, so we need to wait
for the disk to progress to the next state, but `HttpMock` does not
provide a way to programatically delete or update a mock after sending
`n` responses. This means that the disk will always be returned as
non-existing when querying, and cleanup will be skipped. I have opened
alexliesenfeld/httpmock#108 to add a
`delete_after_n` method, but this seems unlikely to be merged. We may
want to consider moving to `wiremock` in the long term, which provides
this functionality.

Co-authored-by: Adam Leventhal <[email protected]>
wfchandler added a commit to oxidecomputer/oxide.rs that referenced this pull request Sep 23, 2024
From a user perspective uploading a disk is a single operation, but
doing so via the SDK is a very involved process, involving stringing
together multiple API calls with any interruption leaving the disk in a
state that cannot be directly removed.

Add a new `extras` module to the SDK that will contain convenience
wrappers around actions that functions that are overly complicated.
Create a `disk_import` function in `extras` that will perform a disk
upload as a single step, and attempts to cleanup partially imported
disks on failure. We make the `disk upload` CLI command a thin wrapper
around the new SDK function, responsible only for cancellation and
progress. We manually recreate the builder interface, as creating a
procmacro to do this would require creating a new crate. If/when
`extras` continues to grow we should reconsider this.

`disk_import` also give callers access to a `DiskImportHandle` with a
`watch` channel with the current number of bytes uploaded for use in
progress tracking, and provides a `cancel` function that allows users
to gracefully stop the disk upload. A disk that has been successfully
created will not be removed, only those that are partially imported.

The `cancel` function uses `tokio::select` to cancel the `Future` of
the upload task. This should be safe in our in our case no locks are
held across `await` points. No operations need to be safe to restart as
we only call `tokio::select` a single time, they will be dropped
immediately and losing a message is not a problem.

We are forced to remove tests `test_disk_import_bulk_import_start_fail`
and `test_disk_import_bulk_write_import_fail` as we now poll for disks
in `Created` state, which may happen if a user immediately cancels a new
request. This state is not eligible to be finalized, so we need to wait
for the disk to progress to the next state, but `HttpMock` does not
provide a way to programatically delete or update a mock after sending
`n` responses. This means that the disk will always be returned as
non-existing when querying, and cleanup will be skipped. I have opened
alexliesenfeld/httpmock#108 to add a
`delete_after_n` method, but this seems unlikely to be merged. We may
want to consider moving to `wiremock` in the long term, which provides
this functionality.

Co-authored-by: Adam Leventhal <[email protected]>
@mothran mothran mentioned this pull request Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants