about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYacin Tmimi <yacintmimi@gmail.com>2022-06-22 13:40:10 -0400
committerCaleb Cartwright <calebcartwright@users.noreply.github.com>2022-06-22 17:45:42 -0500
commita18709156818a1205e9b5f89192808b651c6c59d (patch)
tree5d75bf8eda6fa72cffd473d94ea195edd91a01f6
parent0156575a32511a2d58d129415e9ce31ccb80e7e8 (diff)
downloadrust-a18709156818a1205e9b5f89192808b651c6c59d.tar.gz
rust-a18709156818a1205e9b5f89192808b651c6c59d.zip
Add idempotency test for issue 5399
-rw-r--r--tests/target/issue_5399.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/target/issue_5399.rs b/tests/target/issue_5399.rs
new file mode 100644
index 00000000000..17364c38919
--- /dev/null
+++ b/tests/target/issue_5399.rs
@@ -0,0 +1,48 @@
+// rustfmt-max_width: 140
+
+impl NotificationRepository {
+    fn set_status_changed(
+        &self,
+        repo_tx_conn: &RepoTxConn,
+        rid: &RoutableId,
+        changed_at: NaiveDateTime,
+    ) -> NukeResult<Option<NotificationStatus>> {
+        repo_tx_conn.run(move |conn| {
+            let res = diesel::update(client_notification::table)
+                .filter(
+                    client_notification::routable_id.eq(DieselRoutableId(rid.clone())).and(
+                        client_notification::changed_at
+                            .lt(changed_at)
+                            .or(client_notification::changed_at.is_null()),
+                    ),
+                )
+                .set(client_notification::changed_at.eq(changed_at))
+                .returning((
+                    client_notification::id,
+                    client_notification::changed_at,
+                    client_notification::polled_at,
+                    client_notification::notified_at,
+                ))
+                .get_result::<(Uuid, Option<NaiveDateTime>, Option<NaiveDateTime>, Option<NaiveDateTime>)>(conn)
+                .optional()?;
+
+            match res {
+                Some(row) => {
+                    let client_id = client_contract::table
+                        .inner_join(client_notification::table)
+                        .filter(client_notification::id.eq(row.0))
+                        .select(client_contract::client_id)
+                        .get_result::<Uuid>(conn)?;
+
+                    Ok(Some(NotificationStatus {
+                        client_id: client_id.into(),
+                        changed_at: row.1,
+                        polled_at: row.2,
+                        notified_at: row.3,
+                    }))
+                }
+                None => Ok(None),
+            }
+        })
+    }
+}