You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@texera.apache.org by "aglinxinyuan (via GitHub)" <gi...@apache.org> on 2026/07/31 04:14:14 UTC

[PR] test(amber): cover websocket session state [texera]

aglinxinyuan opened a new pull request, #7157:
URL: https://github.com/apache/texera/pull/7157

   ### What changes were proposed in this PR?
   
   Adds focused unit coverage for websocket event delivery, workflow-service subscription replacement and cleanup, session-map removal, and computing-unit access state.
   
   ### Any related issues, documentation, discussions?
   
   Closes #7153
   
   ### How was this PR tested?
   
   - `WorkflowExecutionService/testOnly org.apache.texera.web.SessionStateSpec` — 3 succeeded.
   - `WorkflowExecutionService/Test/scalafmtCheck` and `WorkflowExecutionService/Test/scalafix --check`.
   
   Mutation proof:
   
   | Production mutation | Result |
   | --- | --- |
   | Replaced the serialized websocket payload with an empty string | 1 test failed |
   | Stopped retaining the subscribed workflow service | 1 test failed |
   | Stopped removing a session from the session-state map | 1 test failed |
   
   Each mutation was reverted before the final green test run.
   
   ### Was this PR authored or co-authored using generative AI tooling?
   
   Generated-by: Codex (GPT-5)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] test(amber): cover websocket session state [texera]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #7157:
URL: https://github.com/apache/texera/pull/7157#discussion_r3689568843


##########
amber/src/test/scala/org/apache/texera/web/SessionStateSpec.scala:
##########
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.web
+
+import io.reactivex.rxjava3.disposables.Disposable
+import org.apache.texera.amber.core.virtualidentity.WorkflowIdentity
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.apache.texera.dao.jooq.generated.enums.PrivilegeEnum
+import org.apache.texera.web.model.websocket.event.{TexeraWebSocketEvent, WorkflowStateEvent}
+import org.apache.texera.web.service.WorkflowService
+import org.scalamock.scalatest.MockFactory
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+import java.util.UUID
+import java.util.concurrent.{Future => JFuture}
+import javax.websocket.{RemoteEndpoint, Session}
+import scala.collection.mutable.ArrayBuffer
+
+class SessionStateSpec extends AnyFlatSpec with Matchers with MockFactory {
+
+  private class TrackingDisposable extends Disposable {
+    var disposeCalls = 0
+
+    override def dispose(): Unit = disposeCalls += 1
+
+    override def isDisposed: Boolean = disposeCalls > 0
+  }
+
+  private class TestWorkflowService(id: Long) extends WorkflowService(WorkflowIdentity(id), 1, 10) {
+    val workflowSubscription = new TrackingDisposable
+    val executionSubscription = new TrackingDisposable
+    var workflowConnectCalls = 0
+    var executionConnectCalls = 0
+    var disconnectCalls = 0
+
+    override def connect(onNext: TexeraWebSocketEvent => Unit): Disposable = {
+      workflowConnectCalls += 1
+      workflowSubscription
+    }
+
+    override def connectToExecution(onNext: TexeraWebSocketEvent => Unit): Disposable = {
+      executionConnectCalls += 1
+      executionSubscription
+    }
+
+    override def disconnect(): Unit = disconnectCalls += 1
+  }
+
+  private def messageCollectingSession(): (Session, ArrayBuffer[String]) = {
+    val messages = ArrayBuffer[String]()
+    val async = mock[RemoteEndpoint.Async]
+    (async
+      .sendText(_: String))
+      .expects(*)
+      .onCall { (message: String) =>
+        messages += message
+        null.asInstanceOf[JFuture[Void]]
+      }
+      .anyNumberOfTimes()
+
+    val session = mock[Session]
+    (() => session.getAsyncRemote).expects().returning(async).anyNumberOfTimes()
+    (session, messages)
+  }
+
+  private def removeStateIfPresent(sessionId: String): Unit = {
+    try {
+      SessionState.removeState(sessionId)
+    } catch {
+      case _: NoSuchElementException =>
+    }
+  }
+
+  "SessionState" should "send websocket events as typed JSON messages" in {
+    val (session, messages) = messageCollectingSession()
+    val state = new SessionState(session)
+
+    state.send(WorkflowStateEvent("RUNNING"))
+
+    messages should have size 1
+    val payload = objectMapper.readTree(messages.head)
+    payload.get("type").asText() shouldBe "WorkflowStateEvent"
+    payload.get("state").asText() shouldBe "RUNNING"
+  }
+
+  it should "replace subscriptions before attaching a new workflow service" in {
+    val state = new SessionState(stub[Session])
+    val firstService = new TestWorkflowService(1L)
+    val secondService = new TestWorkflowService(2L)
+
+    state.subscribe(firstService)
+    state.getCurrentWorkflowState shouldBe Some(firstService)
+    firstService.workflowConnectCalls shouldBe 1
+    firstService.executionConnectCalls shouldBe 1
+
+    state.subscribe(secondService)
+    firstService.workflowSubscription.disposeCalls shouldBe 1
+    firstService.executionSubscription.disposeCalls shouldBe 1
+    firstService.disconnectCalls shouldBe 1
+    state.getCurrentWorkflowState shouldBe Some(secondService)
+    secondService.workflowConnectCalls shouldBe 1
+    secondService.executionConnectCalls shouldBe 1
+
+    state.unsubscribe()
+    secondService.workflowSubscription.disposeCalls shouldBe 1
+    secondService.executionSubscription.disposeCalls shouldBe 1
+    secondService.disconnectCalls shouldBe 1
+    state.getCurrentWorkflowState shouldBe None
+  }
+
+  it should "remove registered sessions and retain their computing-unit access level" in {
+    val sessionId = UUID.randomUUID().toString
+    val state = new SessionState(stub[Session])
+    SessionState.setState(sessionId, state)
+    try {
+      SessionState.getState(sessionId) shouldBe state
+      SessionState.getAllSessionStates should contain(state)
+
+      state.getUserComputingUnitAccess shouldBe PrivilegeEnum.NONE
+      state.setUserComputingUnitAccess(PrivilegeEnum.WRITE)
+      state.getUserComputingUnitAccess shouldBe PrivilegeEnum.WRITE
+
+      SessionState.removeState(sessionId)
+      SessionState.getAllSessionStates should not contain state
+      a[NoSuchElementException] should be thrownBy SessionState.getState(sessionId)
+    } finally {
+      removeStateIfPresent(sessionId)
+    }
+  }

Review Comment:
   This test doesn’t currently verify the cleanup side-effect of `SessionState.removeState`: `removeState` calls `unsubscribe()` before removing the mapping, but the test never subscribes a workflow service, so a regression that drops the `unsubscribe()` call would still pass. Also, the test name suggests the computing-unit access level is retained after removal, but that is not asserted post-removal.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] test(amber): cover websocket session state [texera]

Posted by "aglinxinyuan (via GitHub)" <gi...@apache.org>.
aglinxinyuan merged PR #7157:
URL: https://github.com/apache/texera/pull/7157


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] test(amber): cover websocket session state [texera]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #7157:
URL: https://github.com/apache/texera/pull/7157#issuecomment-5139235621

   <!-- texera-benchmarks-comment -->
   ## ⚠️ Benchmark changes need a look
   
   🟢 2 better · 🔴 1 worse · ⚪ 12 noise (<±5%) · 0 without baseline
   
   > Compared against main `45b7b20` benchmarked on **this same runner**, so the delta is largely free of cross-runner hardware noise. The "7d avg" column still reflects the gh-pages dashboard. Treat <±5% as noise unless repeated.
   
   [Dashboard](https://apache.github.io/texera/dev/bench/) · [Run](https://github.com/apache/texera/actions/runs/30603727414)
   
   | | config | throughput | MB/s | latency | max Δ latest / 7d |
   |---|---|---:|---:|---:|---:|
   | 🔴 | bs=10 sw=10 sl=64 | 385 | 0.235 | 25,514/35,984/35,984 us | 🔴 +6.1% / 🔴 +127.9% |
   | 🟢 | bs=100 sw=10 sl=64 | 780 | 0.476 | 127,587/149,078/149,078 us | 🟢 -10.7% / 🔴 +35.2% |
   | ⚪ | bs=1000 sw=10 sl=64 | 898 | 0.548 | 1,107,728/1,158,281/1,158,281 us | ⚪ within ±5% / 🔴 -10.3% |
   
   <details><summary>Baseline details</summary>
   
   Latest main `45b7b20` from same runner
   
   | config | metric | PR | latest main | 7d avg | Δ latest | Δ 7d |
   |---|---|---:|---:|---:|---:|---:|
   | bs=10 sw=10 sl=64 | throughput | 385 tuples/sec | 384 tuples/sec | 771.62 tuples/sec | +0.3% | -50.1% |
   | bs=10 sw=10 sl=64 | MB/s | 0.235 MB/s | 0.234 MB/s | 0.471 MB/s | +0.4% | -50.1% |
   | bs=10 sw=10 sl=64 | p50 | 25,514 us | 24,040 us | 12,626 us | +6.1% | +102.1% |
   | bs=10 sw=10 sl=64 | p95 | 35,984 us | 37,136 us | 15,786 us | -3.1% | +127.9% |
   | bs=10 sw=10 sl=64 | p99 | 35,984 us | 37,136 us | 19,344 us | -3.1% | +86.0% |
   | bs=100 sw=10 sl=64 | throughput | 780 tuples/sec | 777 tuples/sec | 971.56 tuples/sec | +0.4% | -19.7% |
   | bs=100 sw=10 sl=64 | MB/s | 0.476 MB/s | 0.474 MB/s | 0.593 MB/s | +0.4% | -19.7% |
   | bs=100 sw=10 sl=64 | p50 | 127,587 us | 127,582 us | 103,463 us | +0.0% | +23.3% |
   | bs=100 sw=10 sl=64 | p95 | 149,078 us | 166,876 us | 110,296 us | -10.7% | +35.2% |
   | bs=100 sw=10 sl=64 | p99 | 149,078 us | 166,876 us | 118,690 us | -10.7% | +25.6% |
   | bs=1000 sw=10 sl=64 | throughput | 898 tuples/sec | 910 tuples/sec | 1,001 tuples/sec | -1.3% | -10.3% |
   | bs=1000 sw=10 sl=64 | MB/s | 0.548 MB/s | 0.555 MB/s | 0.611 MB/s | -1.3% | -10.3% |
   | bs=1000 sw=10 sl=64 | p50 | 1,107,728 us | 1,097,216 us | 1,008,988 us | +1.0% | +9.8% |
   | bs=1000 sw=10 sl=64 | p95 | 1,158,281 us | 1,143,127 us | 1,055,260 us | +1.3% | +9.8% |
   | bs=1000 sw=10 sl=64 | p99 | 1,158,281 us | 1,143,127 us | 1,074,689 us | +1.3% | +7.8% |
   
   </details>
   
   <details><summary>Raw CSV</summary>
   
   ```csv
   config_idx,batch_size,schema_width,string_len,num_batches,total_ms,total_tuples,total_bytes,tuples_per_sec,mb_per_sec,lat_p50_us,lat_p95_us,lat_p99_us
   0,10,10,64,20,519.42,200,128000,385,0.235,25513.80,35984.12,35984.12
   1,100,10,64,20,2564.54,2000,1280000,780,0.476,127587.14,149078.34,149078.34
   2,1000,10,64,20,22281.01,20000,12800000,898,0.548,1107728.30,1158281.16,1158281.16
   ```
   
   </details>
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] test(amber): cover websocket session state [texera]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #7157:
URL: https://github.com/apache/texera/pull/7157#issuecomment-5139266001

   ## [Codecov](https://app.codecov.io/gh/apache/texera/pull/7157?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 79.72%. Comparing base ([`45b7b20`](https://app.codecov.io/gh/apache/texera/commit/45b7b20e05864bca98def642e329d501e664413e?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`03d2b6c`](https://app.codecov.io/gh/apache/texera/commit/03d2b6c767323861322bc4dd43edfc26a14507e2?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :white_check_mark: All tests successful. No failed tests found.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff              @@
   ##               main    #7157      +/-   ##
   ============================================
   + Coverage     79.62%   79.72%   +0.09%     
   - Complexity     3836     3855      +19     
   ============================================
     Files          1160     1160              
     Lines         46188    46188              
     Branches       5145     5145              
   ============================================
   + Hits          36777    36823      +46     
   + Misses         7778     7735      -43     
   + Partials       1633     1630       -3     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/texera/pull/7157/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | | *Carryforward flag |
   |---|---|---|---|
   | [access-control-service](https://app.codecov.io/gh/apache/texera/pull/7157/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `70.00% <ø> (ø)` | | Carriedforward from [45b7b20](https://app.codecov.io/gh/apache/texera/commit/45b7b20e05864bca98def642e329d501e664413e?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [agent-service](https://app.codecov.io/gh/apache/texera/pull/7157/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `77.42% <ø> (ø)` | | Carriedforward from [45b7b20](https://app.codecov.io/gh/apache/texera/commit/45b7b20e05864bca98def642e329d501e664413e?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [amber](https://app.codecov.io/gh/apache/texera/pull/7157/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `73.36% <ø> (+0.27%)` | :arrow_up: | |
   | [computing-unit-managing-service](https://app.codecov.io/gh/apache/texera/pull/7157/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `20.49% <ø> (ø)` | | Carriedforward from [45b7b20](https://app.codecov.io/gh/apache/texera/commit/45b7b20e05864bca98def642e329d501e664413e?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [config-service](https://app.codecov.io/gh/apache/texera/pull/7157/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `65.97% <ø> (ø)` | | Carriedforward from [45b7b20](https://app.codecov.io/gh/apache/texera/commit/45b7b20e05864bca98def642e329d501e664413e?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [file-service](https://app.codecov.io/gh/apache/texera/pull/7157/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `66.80% <ø> (ø)` | | Carriedforward from [45b7b20](https://app.codecov.io/gh/apache/texera/commit/45b7b20e05864bca98def642e329d501e664413e?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [frontend](https://app.codecov.io/gh/apache/texera/pull/7157/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `83.16% <ø> (ø)` | | Carriedforward from [45b7b20](https://app.codecov.io/gh/apache/texera/commit/45b7b20e05864bca98def642e329d501e664413e?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [notebook-migration-service](https://app.codecov.io/gh/apache/texera/pull/7157/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `78.89% <ø> (ø)` | | Carriedforward from [45b7b20](https://app.codecov.io/gh/apache/texera/commit/45b7b20e05864bca98def642e329d501e664413e?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [pyamber](https://app.codecov.io/gh/apache/texera/pull/7157/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `97.36% <ø> (ø)` | | Carriedforward from [45b7b20](https://app.codecov.io/gh/apache/texera/commit/45b7b20e05864bca98def642e329d501e664413e?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [workflow-compiling-service](https://app.codecov.io/gh/apache/texera/pull/7157/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `26.31% <ø> (ø)` | | Carriedforward from [45b7b20](https://app.codecov.io/gh/apache/texera/commit/45b7b20e05864bca98def642e329d501e664413e?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   *This pull request uses carry forward flags. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/texera/pull/7157?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] test(amber): cover websocket session state [texera]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #7157:
URL: https://github.com/apache/texera/pull/7157#issuecomment-5139191517

   <!-- texera-reviewer-suggestion -->
   ### Automated Reviewer Suggestions
   
   Based on the `git blame` history of the changed files, we recommend the following reviewers:
   
   - No candidates found from `git blame` history.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org