-
Notifications
You must be signed in to change notification settings - Fork 0
Test Case for Subscription Event Bug #1612
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
Draft
swalker2m
wants to merge
2
commits into
main
Choose a base branch
from
too-many-events
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
modules/service/src/test/scala/lucuma/odb/graphql/subscription/observationEditSn.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| // Copyright (c) 2016-2023 Association of Universities for Research in Astronomy, Inc. (AURA) | ||
| // For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause | ||
|
|
||
| package lucuma.odb.graphql.subscription | ||
|
|
||
| import cats.effect.IO | ||
| import cats.syntax.show.* | ||
| import io.circe.Json | ||
| import io.circe.syntax.* | ||
| import lucuma.core.model.Observation | ||
| import lucuma.core.model.Program | ||
| import lucuma.odb.data.EditType | ||
| import lucuma.odb.graphql.query.ExecutionTestSupport | ||
| import lucuma.odb.graphql.query.ObservingModeSetupOperations | ||
|
|
||
| class observationEditSn extends ExecutionTestSupport with ObservingModeSetupOperations with SubscriptionUtils: | ||
| val AcquisitionTotal: Long = 219362500l | ||
| val ScienceTotal: Long = 784200000l | ||
|
|
||
| def subscriptionQuery(pid: Program.Id) = | ||
| s""" | ||
| subscription { | ||
| observationEdit(input: { programId: "${pid.show}" }) { | ||
| observationId | ||
| editType | ||
| value { | ||
| id | ||
| itc { | ||
| science { | ||
| selected { | ||
| exposureCount | ||
| } | ||
| } | ||
| } | ||
| execution { | ||
| digest { | ||
| acquisition { | ||
| timeEstimate { | ||
| total { microseconds } | ||
| } | ||
| } | ||
| science { | ||
| timeEstimate { | ||
| total { microseconds } | ||
| } | ||
| } | ||
| } | ||
| config { | ||
| gmosNorth { | ||
| science { | ||
| nextAtom { | ||
| observeClass | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| """ | ||
|
|
||
| def subscriptionResponse(oid: Observation.Id): Json = | ||
| Json.obj( | ||
| "observationEdit" -> Json.obj( | ||
| "observationId" -> Json.fromString(oid.show), | ||
| "editType" -> Json.fromString(EditType.Updated.tag.toUpperCase), | ||
| "value" -> Json.obj( | ||
| "id" -> oid.asJson, | ||
| "itc" -> Json.obj( | ||
| "science" -> Json.obj( | ||
| "selected" -> Json.obj( | ||
| "exposureCount" -> 6.asJson | ||
| ) | ||
| ) | ||
| ), | ||
| "execution" -> Json.obj( | ||
| "digest" -> Json.obj( | ||
| "acquisition" -> Json.obj( | ||
| "timeEstimate" -> Json.obj( | ||
| "total" -> Json.obj( | ||
| "microseconds" -> AcquisitionTotal.asJson | ||
| ) | ||
| ) | ||
| ), | ||
| "science" -> Json.obj( | ||
| "timeEstimate" -> Json.obj( | ||
| "total" -> Json.obj( | ||
| "microseconds" -> ScienceTotal.asJson | ||
| ) | ||
| ) | ||
| ) | ||
| ), | ||
| "config" -> Json.obj( | ||
| "gmosNorth" -> Json.obj( | ||
| "science" -> Json.obj( | ||
| "nextAtom" -> Json.obj( | ||
| "observeClass" -> "SCIENCE".asJson | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| def updateSn( | ||
| oid: Observation.Id | ||
| ): IO[Unit] = | ||
| query( | ||
| user = pi, | ||
| query = s""" | ||
| mutation { | ||
| updateObservations(input: { | ||
| SET: { | ||
| scienceRequirements: { | ||
| spectroscopy: { | ||
| wavelength: { micrometers: 0.700000 } | ||
| resolution: 1000 | ||
| exposureTimeMode: { | ||
| signalToNoise: { | ||
| value: 99 | ||
| at: { nanometers: 500 } | ||
| } | ||
| } | ||
| wavelengthCoverage: { micrometers: 0.400000 } | ||
| focalPlane: null | ||
| focalPlaneAngle: null | ||
| capability: null | ||
| } | ||
| } | ||
| }, | ||
| WHERE: { | ||
| id: { EQ: "$oid" } | ||
| } | ||
| }) { | ||
| observations { | ||
| scienceRequirements { | ||
| spectroscopy { | ||
| exposureTimeMode { | ||
| signalToNoise { | ||
| value | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| """ | ||
| ).void | ||
|
|
||
| test("triggers for editing s/n"): | ||
| for | ||
| pid <- createProgram(pi, "foo") | ||
| tid <- createTargetWithProfileAs(pi, pid) | ||
| oid <- createGmosNorthLongSlitObservationAs(pi, pid, List(tid)) | ||
| _ <- generateOrFail(pid, oid) | ||
| _ <- subscriptionExpect( | ||
| user = pi, | ||
| query = subscriptionQuery(pid), | ||
| mutations = Right(sleep >> updateSn(oid)), | ||
| expected = List(subscriptionResponse(oid), subscriptionResponse(oid)) | ||
| ) | ||
| yield () |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may not be a great idea after all. By the time the event is fired, the expected subscription query can produce different results than it would have if it had been generated immediately. For example, when a new group is created without specifying a parent index, it defaults to index 0. It may be subsequently moved. Then the group creation event fires after the
GroupingTimeoutexpires. At that point, the index is no longer 0. So you can see aCREATEDevent with parent index 1 followed by anUPDATEDevent also at 1 when you expectedCREATEDat 0 followed upUPDATEDshowing 1.I don't know whether this is a problem for production, but it definitely makes tests unpredictable.