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

Fix TestProvisioningFactoryReset when running with libfaketime #1371

Merged
merged 1 commit into from
Sep 12, 2024

Conversation

Danielius1922
Copy link
Member

No description provided.

Copy link
Contributor

coderabbitai bot commented Sep 11, 2024

Walkthrough

The changes involve modifying the instantiation of the devClient in the TestProvisioningFactoryReset function to include an additional validity parameter in the sdk.NewClient function call. This parameter specifies a start time and duration for the client, which is necessary for testing scenarios that utilize libfaketime. Additionally, several functions across different files have been updated to use a new utility function for type casting, enhancing type safety. The changes also include adjustments to data types from signed to unsigned integers in various methods.

Changes

Files Change Summary
device-provisioning-service/service/provision_test.go Updated devClient instantiation in TestProvisioningFactoryReset to include a validity period in sdk.NewClient. Modified the function signature of NewClient in the sdk package to accept the new parameter.
cloud2cloud-connector/service/pull.go, cloud2cloud-connector/service/retrieveResource.go, cloud2cloud-connector/service/updateResource.go Replaced direct assignment of Sequence with math.CastTo[uint64](time.Now().UnixNano()) for type safety.
cloud2cloud-gateway/store/mongodb/store.go Changed return statement in incrementSubscriptionSequenceNumber to use math.CastTo[uint64](value.(int64)) for type safety.
resource-aggregate/cqrs/aggregate/aggregate.go Updated HandleCommandWithAggregateModelWrapper to use math.CastTo[uint64] for version calculation in snapshotting.
resource-aggregate/cqrs/eventstore/cqldb/load.go Replaced direct conversion of version to uint64 with math.CastTo[uint64](version) in Next method.
resource-aggregate/cqrs/eventstore/mongodb/load.go Changed return types of getEvent, nextEvent, and check methods from int64 to uint64.
resource-aggregate/cqrs/eventstore/mongodb/maintenance.go Updated assignment of task.Version in Next method to use math.CastTo[uint64](version).
resource-aggregate/cqrs/utils/utils.go Simplified TimeNowMs function to use math.CastTo[uint64] for casting the result of time.Now().UnixNano().
tools/mongodb/standby-tool/main.go Removed //nolint:gosec comment directive from getValue function.

Possibly related PRs

Poem

🐇 In the realm of code where bunnies play,
A new client springs forth, brightening the day.
With time set just right, it hops into place,
Testing with vigor, it quickens the pace.
So here's to the changes, let joy now abound,
For in every line, a new friend is found! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Danielius1922 Danielius1922 marked this pull request as ready for review September 11, 2024 17:46
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c5a82d3 and 74aa474.

Files selected for processing (11)
  • cloud2cloud-connector/service/pull.go (4 hunks)
  • cloud2cloud-connector/service/retrieveResource.go (2 hunks)
  • cloud2cloud-connector/service/updateResource.go (2 hunks)
  • cloud2cloud-gateway/store/mongodb/store.go (2 hunks)
  • device-provisioning-service/service/provision_test.go (1 hunks)
  • resource-aggregate/cqrs/aggregate/aggregate.go (2 hunks)
  • resource-aggregate/cqrs/eventstore/cqldb/load.go (2 hunks)
  • resource-aggregate/cqrs/eventstore/mongodb/load.go (5 hunks)
  • resource-aggregate/cqrs/eventstore/mongodb/maintenance.go (2 hunks)
  • resource-aggregate/cqrs/utils/utils.go (2 hunks)
  • tools/mongodb/standby-tool/main.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • device-provisioning-service/service/provision_test.go
Additional context used
Learnings (1)
tools/mongodb/standby-tool/main.go (1)
Learnt from: jkralik
PR: plgd-dev/hub#1365
File: tools/mongodb/standby-tool/main.go:505-505
Timestamp: 2024-08-21T19:04:41.104Z
Learning: The `//nolint:gosec` directive in the `tools/mongodb/standby-tool/main.go` file is necessary for Golangci-lint and should not be removed.
Additional comments not posted (15)
cloud2cloud-gateway/store/mongodb/store.go (2)

9-9: LGTM!

The import statement for the math package is valid and follows the correct syntax.


55-55: LGTM!

The changes to the return statement are approved for the following reasons:

  • The usage of the math.CastTo function for type casting enhances type safety and clarity.
  • The function call syntax is correct and the types are properly specified.
  • The subtraction of 1 from the casted value is performed correctly.
cloud2cloud-connector/service/retrieveResource.go (1)

70-70: LGTM, but verify the behavior of math.CastTo.

The change introduces a utility function math.CastTo for type casting, which may provide additional type safety or functionality compared to direct type conversion.

However, ensure that the behavior of math.CastTo aligns with the expected functionality of converting the current timestamp in nanoseconds to uint64.

Run the following script to verify the behavior of math.CastTo:

Verification successful

The use of math.CastTo is correct and aligns with the expected functionality.

The math.CastTo function is a generic utility for casting between integer types, ensuring type safety. It correctly converts the current timestamp in nanoseconds to uint64, maintaining the intended functionality.

  • Implementation of math.CastTo:
    • File: internal/math/cast.go
    • Function: func CastTo[T, F constraints.Integer](from F) T { return T(from) }
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the behavior of `math.CastTo` for converting int64 to uint64.

# Test: Search for the implementation of `math.CastTo`. Expect: The function should correctly convert int64 to uint64.
ast-grep --lang go --pattern $'func CastTo[$_]($_) $_ {
  $$$
}'

Length of output: 205

resource-aggregate/cqrs/eventstore/mongodb/maintenance.go (1)

90-90: LGTM!

The change to use the math.CastTo[uint64] function for type casting enhances type safety and is consistent with the AI-generated summary.

cloud2cloud-connector/service/updateResource.go (1)

92-92: LGTM!

The change to use math.CastTo[uint64](time.Now().UnixNano()) for populating the Sequence field in the CommandMetadata struct is an improvement over the previous approach. It enhances type safety and consistency in handling type conversions across the codebase by leveraging a dedicated casting function from the math package.

The overall logic of the function remains intact, and the change only refines the method of obtaining the Sequence value.

resource-aggregate/cqrs/utils/utils.go (1)

83-84: LGTM!

The changes to the TimeNowMs function are approved.

The modifications simplify the function implementation, making it more readable and efficient. The use of the math.CastTo[uint64] function enhances type safety and clarity regarding the expected return type.

resource-aggregate/cqrs/eventstore/cqldb/load.go (2)

12-12: LGTM!

The addition of the math package import is approved.


87-87: LGTM!

The modification of the type conversion from uint64(version) to math.CastTo[uint64](version) is approved.

The change enhances type safety and robustness by leveraging the functionality provided by the math package.

resource-aggregate/cqrs/aggregate/aggregate.go (1)

205-206: LGTM!

The change enhances type safety by explicitly converting the length of newEvents to uint64 before adding it to newVersion. This may prevent potential issues related to type mismatches and refines the logic for snapshot handling, emphasizing type correctness.

The code changes are approved.

cloud2cloud-connector/service/pull.go (3)

123-123: LGTM!

The change to use the math.CastTo function for type conversion is approved. It enhances type safety and provides a consistent approach to handling type conversions.


238-238: LGTM!

The change to use the math.CastTo function for type conversion is approved. It enhances type safety and provides a consistent approach to handling type conversions.


307-307: LGTM!

The change to use the math.CastTo function for type conversion is approved. It enhances type safety and provides a consistent approach to handling type conversions.

resource-aggregate/cqrs/eventstore/mongodb/load.go (3)

Line range hint 74-83: LGTM!

The changes to the getEvent method are approved:

  • The return type has been correctly updated to use uint64 for the version.
  • The math.CastTo[uint64] function is used to safely cast the version from int64 to uint64.

86-88: LGTM!

The changes to the nextEvent method are approved:

  • The return type has been correctly updated to use uint64 for the version.

189-200: LGTM!

The changes to the check method are approved:

  • The version parameter type has been correctly updated to uint64.
  • Removing the explicit type conversion when comparing version against v improves code readability and is safe since both are now of the same type.

tools/mongodb/standby-tool/main.go Show resolved Hide resolved
Copy link

sonarcloud bot commented Sep 11, 2024

@Danielius1922 Danielius1922 merged commit bd44498 into main Sep 12, 2024
42 checks passed
@Danielius1922 Danielius1922 deleted the adam/feature/dps-faketime branch September 12, 2024 07:12
@coderabbitai coderabbitai bot mentioned this pull request Sep 16, 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.

1 participant