diff --git a/CHANGELOG.md b/CHANGELOG.md index c5dc11cffd47..a8653d926509 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -372,6 +372,7 @@ - [Invalidate module's IR cache if imported module changed][3703] - [Don't rename imported Main module that only imports names][3710] - [Distinguish static and instance methods][3740] +- [Notify node status to the IDE][3729] [3227]: https://github.com/enso-org/enso/pull/3227 [3248]: https://github.com/enso-org/enso/pull/3248 @@ -418,8 +419,9 @@ [3658]: https://github.com/enso-org/enso/pull/3658 [3671]: https://github.com/enso-org/enso/pull/3671 [3696]: https://github.com/enso-org/enso/pull/3696 -[3696]: https://github.com/enso-org/enso/pull/3703 -[3696]: https://github.com/enso-org/enso/pull/3710 +[3703]: https://github.com/enso-org/enso/pull/3703 +[3710]: https://github.com/enso-org/enso/pull/3710 +[3729]: https://github.com/enso-org/enso/pull/3729 [3740]: https://github.com/enso-org/enso/pull/3740 # Enso 2.0.0-alpha.18 (2021-10-12) diff --git a/app/gui/controller/engine-protocol/src/language_server/types.rs b/app/gui/controller/engine-protocol/src/language_server/types.rs index 889dcb9b589d..e7c98cf41c55 100644 --- a/app/gui/controller/engine-protocol/src/language_server/types.rs +++ b/app/gui/controller/engine-protocol/src/language_server/types.rs @@ -236,6 +236,11 @@ pub enum ExpressionUpdatePayload { message: String, trace: Vec, }, + #[serde(rename_all = "camelCase")] + Pending { + message: Option, + progress: Option, + }, } diff --git a/app/gui/src/presenter/graph/state.rs b/app/gui/src/presenter/graph/state.rs index f29027e75ca5..4e5cd654d818 100644 --- a/app/gui/src/presenter/graph/state.rs +++ b/app/gui/src/presenter/graph/state.rs @@ -299,7 +299,7 @@ impl Expressions { /// /// This structure keeps the information how the particular graph elements received from controllers /// are represented in the view. It also handles updates from the controllers and -/// the view in `update_from_controller` and `update_from_view` respectively. +/// the view in `update_from_controller` and `update_from_view` respectively. #[derive(Clone, Debug, Default)] pub struct State { nodes: RefCell, @@ -492,6 +492,7 @@ impl<'a> ControllerChange<'a> { None | Some(Value) => None, Some(DataflowError { trace }) => Some((Kind::Dataflow, None, trace)), Some(Panic { message, trace }) => Some((Kind::Panic, Some(message), trace)), + Some(Pending { .. }) => None, }?; let propagated = if kind == Kind::Panic { let nodes = self.nodes.borrow(); @@ -681,7 +682,7 @@ impl<'a> ViewChange<'a> { impl<'a> ViewChange<'a> { /// If the connections does not already exist, it is created and corresponding to-be-created - /// Ast connection is returned. + /// Ast connection is returned. pub fn create_connection(&self, connection: view::graph_editor::Edge) -> Option { let source = connection.source()?; let target = connection.target()?; @@ -689,7 +690,7 @@ impl<'a> ViewChange<'a> { } /// If the connections with provided endpoints does not already exist, it is created and - /// corresponding to-be-created Ast connection is returned. + /// corresponding to-be-created Ast connection is returned. pub fn create_connection_from_endpoints( &self, connection: ViewConnection, diff --git a/docs/language-server/protocol-language-server.md b/docs/language-server/protocol-language-server.md index 9c6cd9bf1c97..39555d6e547c 100644 --- a/docs/language-server/protocol-language-server.md +++ b/docs/language-server/protocol-language-server.md @@ -341,7 +341,7 @@ interface ExpressionUpdate { An information about the computed value. ```typescript -type ExpressionUpdatePayload = Value | DatafalowError | Panic; +type ExpressionUpdatePayload = Value | DatafalowError | Panic | Pending; /** * An empty payload. Indicates that the expression was computed to a value. @@ -372,6 +372,22 @@ interface Panic { */ trace: ExpressionId[]; } + +/** + * Indicates the expression is currently being computed. Optionally it + * provides description and percentage (`0.0-1.0`) of completeness. + */ +interface Pending { + /** + * Optional message describing current operation. + */ + message?: String; + + /** + * Optional amount of already done work as a number between `0.0` to `1.0`. + */ + progress?: Number; +} ``` ### `VisualisationConfiguration` diff --git a/engine/language-server/src/main/scala/org/enso/languageserver/runtime/ContextEventsListener.scala b/engine/language-server/src/main/scala/org/enso/languageserver/runtime/ContextEventsListener.scala index 3c0ec78f28a5..c08d93a45152 100644 --- a/engine/language-server/src/main/scala/org/enso/languageserver/runtime/ContextEventsListener.scala +++ b/engine/language-server/src/main/scala/org/enso/languageserver/runtime/ContextEventsListener.scala @@ -247,6 +247,9 @@ final class ContextEventsListener( case Api.ExpressionUpdate.Payload.Value() => ContextRegistryProtocol.ExpressionUpdate.Payload.Value + case Api.ExpressionUpdate.Payload.Pending(m, p) => + ContextRegistryProtocol.ExpressionUpdate.Payload.Pending(m, p) + case Api.ExpressionUpdate.Payload.DataflowError(trace) => ContextRegistryProtocol.ExpressionUpdate.Payload.DataflowError(trace) diff --git a/engine/language-server/src/main/scala/org/enso/languageserver/runtime/ContextRegistryProtocol.scala b/engine/language-server/src/main/scala/org/enso/languageserver/runtime/ContextRegistryProtocol.scala index 610e843cac5a..ab534b21119b 100644 --- a/engine/language-server/src/main/scala/org/enso/languageserver/runtime/ContextRegistryProtocol.scala +++ b/engine/language-server/src/main/scala/org/enso/languageserver/runtime/ContextRegistryProtocol.scala @@ -161,6 +161,9 @@ object ContextRegistryProtocol { /** An information about computed expression. */ case object Value extends Payload + case class Pending(message: Option[String], progress: Option[Double]) + extends Payload; + /** Indicates that the expression was computed to an error. * * @param trace the list of expressions leading to the root error. @@ -186,6 +189,8 @@ object ContextRegistryProtocol { val Value = "Value" + val Pending = "Pending" + val DataflowError = "DataflowError" val Panic = "Panic" @@ -210,6 +215,13 @@ object ContextRegistryProtocol { .deepMerge( Json.obj(CodecField.Type -> PayloadType.Panic.asJson) ) + + case m: Payload.Pending => + Encoder[Payload.Pending] + .apply(m) + .deepMerge( + Json.obj(CodecField.Type -> PayloadType.Pending.asJson) + ) } implicit val decoder: Decoder[Payload] = @@ -223,6 +235,9 @@ object ContextRegistryProtocol { case PayloadType.Panic => Decoder[Payload.Panic].tryDecode(cursor) + + case PayloadType.Pending => + Decoder[Payload.Pending].tryDecode(cursor) } } } diff --git a/engine/polyglot-api/src/main/scala/org/enso/polyglot/runtime/Runtime.scala b/engine/polyglot-api/src/main/scala/org/enso/polyglot/runtime/Runtime.scala index 1906c98c66e2..88a96578e7fa 100644 --- a/engine/polyglot-api/src/main/scala/org/enso/polyglot/runtime/Runtime.scala +++ b/engine/polyglot-api/src/main/scala/org/enso/polyglot/runtime/Runtime.scala @@ -367,6 +367,10 @@ object Runtime { new JsonSubTypes.Type( value = classOf[Payload.Panic], name = "expressionUpdatePayloadPanic" + ), + new JsonSubTypes.Type( + value = classOf[Payload.Pending], + name = "expressionUpdatePayloadPending" ) ) ) @@ -378,6 +382,11 @@ object Runtime { */ case class Value() extends Payload + /** TBD + */ + case class Pending(message: Option[String], progress: Option[Double]) + extends Payload; + /** Indicates that the expression was computed to an error. * * @param trace the list of expressions leading to the root error. diff --git a/engine/runtime-instrument-id-execution/src/main/java/org/enso/interpreter/instrument/IdExecutionInstrument.java b/engine/runtime-instrument-id-execution/src/main/java/org/enso/interpreter/instrument/IdExecutionInstrument.java index d6cd7515e5c2..230ea88df9ee 100644 --- a/engine/runtime-instrument-id-execution/src/main/java/org/enso/interpreter/instrument/IdExecutionInstrument.java +++ b/engine/runtime-instrument-id-execution/src/main/java/org/enso/interpreter/instrument/IdExecutionInstrument.java @@ -205,9 +205,7 @@ private void onExpressionReturn(Object result, Node node, EventContext context) ExpressionValue expressionValue = new ExpressionValue( nodeId, result, resultType, cachedType, call, cachedCall, profilingInfo, false); - if (expressionValue.isTypeChanged() || expressionValue.isFunctionCallChanged()) { - syncState.setExpressionUnsync(nodeId); - } + syncState.setExpressionUnsync(nodeId); syncState.setVisualisationUnsync(nodeId); // Panics are not cached because a panic can be fixed by changing seemingly unrelated code, diff --git a/engine/runtime-with-instruments/src/test/java/org/enso/interpreter/test/instrument/IncrementalUpdatesTest.java b/engine/runtime-with-instruments/src/test/java/org/enso/interpreter/test/instrument/IncrementalUpdatesTest.java index d1fe20e575ef..7519b765c512 100644 --- a/engine/runtime-with-instruments/src/test/java/org/enso/interpreter/test/instrument/IncrementalUpdatesTest.java +++ b/engine/runtime-with-instruments/src/test/java/org/enso/interpreter/test/instrument/IncrementalUpdatesTest.java @@ -16,6 +16,7 @@ import org.enso.polyglot.runtime.Runtime$Api$CreateContextResponse; import org.enso.polyglot.runtime.Runtime$Api$EditFileNotification; import org.enso.polyglot.runtime.Runtime$Api$ExecutionFailed; +import org.enso.polyglot.runtime.Runtime$Api$ExpressionUpdates; import org.enso.polyglot.runtime.Runtime$Api$InitializedNotification; import org.enso.polyglot.runtime.Runtime$Api$MethodPointer; import org.enso.polyglot.runtime.Runtime$Api$OpenFileNotification; @@ -35,6 +36,8 @@ import scala.Option; import scala.collection.immutable.List; import scala.collection.immutable.Seq; +import scala.collection.immutable.Set; +import scala.collection.immutable.Set$; import scala.collection.immutable.Vector1; public class IncrementalUpdatesTest { @@ -168,7 +171,7 @@ private static String extractPositions(String code, String chars, Map registerRegion = (ch) -> { int[] beginAndLength = pos.get(ch); - return metadata.addItem(beginAndLength[0], beginAndLength[1]); + return metadata.addItem(beginAndLength[0], beginAndLength[1], null); }; // foo definition registerRegion.apply('&'); @@ -213,10 +216,10 @@ private static String extractPositions(String code, String chars, Map sendExpressionValue(String originalText, String newText) { @@ -281,7 +284,7 @@ private static String extractPositions(String code, String chars, Map T findLiteralNode(Class type, Map> nodes) { @@ -295,6 +298,11 @@ private static void assertSameElements(List actual, Runtim assertEquals("Same size: " + actual, seq.length, actual.size()); for (int i = 0; i < seq.length; i++) { var real = actual.drop(i).head(); + if (real instanceof Runtime$Api$Response response) { + if (response.payload() instanceof Runtime$Api$ExpressionUpdates) { + continue; + } + } assertEquals("Check on #" + i, seq[i], real); } } @@ -313,6 +321,10 @@ private static Option None() { return (Option) scala.None$.MODULE$; } + private static Set emptySet() { + return Set$.MODULE$.empty(); + } + private static Runtime$Api$Request Request(UUID id, org.enso.polyglot.runtime.Runtime.ApiRequest request) { return org.enso.polyglot.runtime.Runtime$Api$Request$.MODULE$.apply(id, request); } diff --git a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/BuiltinTypesTest.scala b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/BuiltinTypesTest.scala index 5289b6f18eba..25fc0fa5a63d 100644 --- a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/BuiltinTypesTest.scala +++ b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/BuiltinTypesTest.scala @@ -163,7 +163,9 @@ class BuiltinTypesTest runCode(contextId, requestId, contents) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, idMain, ConstantsGen.INTEGER), context.executionComplete(contextId) @@ -187,7 +189,9 @@ class BuiltinTypesTest runCode(contextId, requestId, contents) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, idMain, ConstantsGen.DECIMAL), context.executionComplete(contextId) @@ -211,7 +215,9 @@ class BuiltinTypesTest runCode(contextId, requestId, contents) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, idMain, ConstantsGen.BOOLEAN), context.executionComplete(contextId) @@ -235,7 +241,9 @@ class BuiltinTypesTest runCode(contextId, requestId, contents) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, idMain, ConstantsGen.TEXT), context.executionComplete(contextId) @@ -261,7 +269,9 @@ class BuiltinTypesTest runCode(contextId, requestId, contents) - context.receiveNIgnoreStdLib(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, idY, ConstantsGen.FUNCTION), TestMessages.update(contextId, idMain, ConstantsGen.INTEGER), @@ -290,7 +300,9 @@ class BuiltinTypesTest runCode(contextId, requestId, contents) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, idMain, "Enso_Test.Test.Main.Foo.Bar"), context.executionComplete(contextId) @@ -318,7 +330,9 @@ class BuiltinTypesTest runCode(contextId, requestId, contents) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, idMain, "Enso_Test.Test.Main.Foo.Bar"), context.executionComplete(contextId) @@ -342,7 +356,9 @@ class BuiltinTypesTest runCode(contextId, requestId, contents) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, idMain, ConstantsGen.ARRAY), context.executionComplete(contextId) @@ -366,7 +382,9 @@ class BuiltinTypesTest runCode(contextId, requestId, contents) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, idMain, ConstantsGen.VECTOR), context.executionComplete(contextId) @@ -390,7 +408,9 @@ class BuiltinTypesTest runCode(contextId, requestId, contents) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, idMain, ConstantsGen.REF), context.executionComplete(contextId) @@ -414,7 +434,9 @@ class BuiltinTypesTest runCode(contextId, requestId, contents) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, idMain, ConstantsGen.DATE), context.executionComplete(contextId) @@ -438,7 +460,9 @@ class BuiltinTypesTest runCode(contextId, requestId, contents) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, idMain, ConstantsGen.DATE_TIME), context.executionComplete(contextId) @@ -462,7 +486,9 @@ class BuiltinTypesTest runCode(contextId, requestId, contents) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, idMain, ConstantsGen.TIME_OF_DAY), context.executionComplete(contextId) @@ -486,7 +512,9 @@ class BuiltinTypesTest runCode(contextId, requestId, contents) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, idMain, ConstantsGen.TIME_ZONE), context.executionComplete(contextId) @@ -510,7 +538,9 @@ class BuiltinTypesTest runCode(contextId, requestId, contents) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, idMain, ConstantsGen.NOTHING), context.executionComplete(contextId) diff --git a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeErrorsTest.scala b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeErrorsTest.scala index a3330169a334..48ebadeaf844 100644 --- a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeErrorsTest.scala +++ b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeErrorsTest.scala @@ -167,7 +167,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveN(6) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 6 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.ExecutionUpdate( @@ -251,7 +253,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveN(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.ExecutionUpdate( @@ -330,7 +334,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.error( contextId, @@ -397,7 +403,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveNIgnoreStdLib(6) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 6 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.ExecutionUpdate( @@ -480,7 +488,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveNIgnoreStdLib(6) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 6 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.ExecutionUpdate( @@ -554,7 +564,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.error( contextId, @@ -586,7 +598,10 @@ class RuntimeErrorsTest ) ) ) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3, + updatesOnlyFor = Set(xId, yId) + ) should contain theSameElementsAs Seq( TestMessages.update(contextId, xId, ConstantsGen.INTEGER), TestMessages.update(contextId, yId, ConstantsGen.INTEGER), context.executionComplete(contextId) @@ -608,7 +623,10 @@ class RuntimeErrorsTest ) ) ) - context.receiveN(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3, + updatesOnlyFor = Set(xId, yId) + ) should contain theSameElementsAs Seq( TestMessages.error( contextId, xId, @@ -640,7 +658,10 @@ class RuntimeErrorsTest ) ) ) - context.receiveN(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3, + updatesOnlyFor = Set(xId, yId) + ) should contain theSameElementsAs Seq( TestMessages.update(contextId, xId, ConstantsGen.INTEGER), TestMessages.update(contextId, yId, ConstantsGen.INTEGER), context.executionComplete(contextId) @@ -697,7 +718,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.error( contextId, @@ -729,7 +752,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveN(1) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 1 + ) should contain theSameElementsAs Seq( context.executionComplete(contextId) ) context.consumeOut shouldEqual List("(Error: MyError2)") @@ -788,7 +813,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.error( contextId, @@ -821,7 +848,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveN(1) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 1 + ) should contain theSameElementsAs Seq( context.executionComplete(contextId) ) context.consumeOut shouldEqual List("(Error: MyError2)") @@ -875,7 +904,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.panic( contextId, @@ -921,7 +952,9 @@ class RuntimeErrorsTest ) ) - context.receiveNIgnoreStdLib(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( TestMessages.update(contextId, xId, ConstantsGen.INTEGER), TestMessages.update(contextId, yId, ConstantsGen.INTEGER), TestMessages.update(contextId, mainResId, ConstantsGen.NOTHING), @@ -976,7 +1009,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveNIgnoreStdLib(6) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 6 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.ExecutionUpdate( @@ -1034,7 +1069,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveN(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( TestMessages.update(contextId, xId, ConstantsGen.INTEGER), TestMessages.update(contextId, yId, ConstantsGen.INTEGER), TestMessages.update(contextId, mainResId, ConstantsGen.NOTHING), @@ -1093,7 +1130,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.panic( contextId, @@ -1138,7 +1177,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveN(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( TestMessages.panic( contextId, xId, @@ -1217,7 +1258,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.panic( contextId, @@ -1263,7 +1306,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveN(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( TestMessages.update( contextId, xId, @@ -1327,7 +1372,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.error( contextId, @@ -1364,7 +1411,10 @@ class RuntimeErrorsTest ) ) ) - context.receiveN(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3, + updatesOnlyFor = Set(xId, yId) + ) should contain theSameElementsAs Seq( TestMessages.update( contextId, xId, @@ -1423,7 +1473,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveN(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.ExecutionUpdate( @@ -1473,7 +1525,9 @@ class RuntimeErrorsTest ) ) ) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( TestMessages.update(contextId, x1Id, ConstantsGen.NOTHING), TestMessages.update(contextId, mainRes1Id, ConstantsGen.NOTHING), context.executionComplete(contextId) diff --git a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeInstrumentTest.scala b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeInstrumentTest.scala index 4f9cdef582bc..e618eacc1c9e 100644 --- a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeInstrumentTest.scala +++ b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeInstrumentTest.scala @@ -313,7 +313,9 @@ class RuntimeInstrumentTest ) ) ) - context.receiveNIgnoreStdLib(7) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 7 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, xExpr, ConstantsGen.INTEGER), TestMessages.update(contextId, yExpr, ConstantsGen.INTEGER), @@ -373,7 +375,9 @@ class RuntimeInstrumentTest ) ) ) - context.receiveNIgnoreStdLib(7) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 7 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, xExpr, ConstantsGen.INTEGER), TestMessages.update(contextId, yExpr, ConstantsGen.INTEGER), @@ -430,7 +434,9 @@ class RuntimeInstrumentTest ) ) ) - context.receiveN(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, fExpr, ConstantsGen.FUNCTION), TestMessages.update(contextId, mainResExpr, ConstantsGen.INTEGER), @@ -543,7 +549,9 @@ class RuntimeInstrumentTest ) ) ) - context.receiveN(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages .update( @@ -608,7 +616,9 @@ class RuntimeInstrumentTest ) ) ) - context.receiveNIgnoreStdLib(6) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 6 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, aExpr, ConstantsGen.INTEGER), TestMessages.update(contextId, fApp, ConstantsGen.INTEGER), @@ -668,7 +678,9 @@ class RuntimeInstrumentTest ) ) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, aExpr, ConstantsGen.INTEGER), TestMessages.update(contextId, lamArg, ConstantsGen.INTEGER), @@ -725,7 +737,9 @@ class RuntimeInstrumentTest ) ) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, aExpr, ConstantsGen.INTEGER), TestMessages.update(contextId, lamArg, ConstantsGen.INTEGER), @@ -974,7 +988,9 @@ class RuntimeInstrumentTest ) ) ) - context.receiveN(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, arg1, ConstantsGen.INTEGER), TestMessages.update(contextId, arg2, ConstantsGen.INTEGER), diff --git a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeServerTest.scala b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeServerTest.scala index ab0b5ce3631d..e03b985fccfa 100644 --- a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeServerTest.scala +++ b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeServerTest.scala @@ -118,11 +118,11 @@ class RuntimeServerTest val metadata = new Metadata - val idMainX = metadata.addItem(63, 1) - val idMainY = metadata.addItem(73, 7) - val idMainZ = metadata.addItem(89, 5) - val idFooY = metadata.addItem(133, 8) - val idFooZ = metadata.addItem(150, 5) + val idMainX = metadata.addItem(63, 1, "aa1") + val idMainY = metadata.addItem(73, 7, "aa2") + val idMainZ = metadata.addItem(89, 5, "aa3") + val idFooY = metadata.addItem(133, 8, "ff2") + val idFooZ = metadata.addItem(150, 5, "ff3") def code = metadata.appendToCode( @@ -161,7 +161,31 @@ class RuntimeServerTest ) ) - def mainY(contextId: UUID, fromCache: Boolean = false): Api.Response = + def pendingZ(): Api.ExpressionUpdate = + Api.ExpressionUpdate( + Main.idFooZ, + None, + None, + Vector(), + true, + Api.ExpressionUpdate.Payload.Pending(None, None) + ) + + def pendingY(): Api.ExpressionUpdate = + Api.ExpressionUpdate( + Main.idFooY, + None, + None, + Vector(), + true, + Api.ExpressionUpdate.Payload.Pending(None, None) + ) + + def mainY( + contextId: UUID, + fromCache: Boolean = false, + noPointer: Boolean = false + ): Api.Response = Api.Response( Api.ExpressionUpdates( contextId, @@ -169,13 +193,15 @@ class RuntimeServerTest Api.ExpressionUpdate( Main.idMainY, Some(ConstantsGen.INTEGER), - Some( - Api.MethodPointer( - "Enso_Test.Test.Main", - ConstantsGen.NUMBER, - "foo" - ) - ), + if (noPointer) None + else + Some( + Api.MethodPointer( + "Enso_Test.Test.Main", + ConstantsGen.NUMBER, + "foo" + ) + ), Vector(Api.ProfilingInfo.ExecutionTime(0)), fromCache, Api.ExpressionUpdate.Payload.Value() @@ -357,7 +383,9 @@ class RuntimeServerTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -370,7 +398,9 @@ class RuntimeServerTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item2)) ) - context.receiveN(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.fooY(contextId), context.Main.Update.fooZ(contextId), @@ -395,8 +425,19 @@ class RuntimeServerTest // pop foo call context.send(Api.Request(requestId, Api.PopContextRequest(contextId))) - context.receiveN(3) should contain theSameElementsAs Seq( + context.receiveN(5) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PopContextResponse(contextId)), + Api.Response( + None, + Api.ExpressionUpdates( + contextId, + Set( + context.Main.Update.pendingY(), + context.Main.Update.pendingZ() + ) + ) + ), + context.Main.Update.mainY(contextId, fromCache = true, noPointer = true), context.Main.Update.mainY(contextId, fromCache = true), context.executionComplete(contextId) ) @@ -459,7 +500,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, idFoo, ConstantsGen.INTEGER), context.executionComplete(contextId) @@ -513,7 +556,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update( contextId, @@ -533,7 +578,9 @@ class RuntimeServerTest Api.PushContextRequest(contextId, Api.StackItem.LocalCall(idMainFoo)) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.executionComplete(contextId) ) @@ -616,7 +663,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(9) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 9 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update( contextId, @@ -757,7 +806,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update( contextId, @@ -818,7 +869,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update( contextId, @@ -881,7 +934,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update( contextId, @@ -940,7 +995,9 @@ class RuntimeServerTest ) ) ) - context.receiveN(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update( contextId, @@ -1008,7 +1065,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages .update( @@ -1029,7 +1088,9 @@ class RuntimeServerTest Api.PushContextRequest(contextId, Api.StackItem.LocalCall(mainFoo)) ) ) - context.receiveN(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, fooX, ConstantsGen.INTEGER), TestMessages.update(contextId, fooRes, ConstantsGen.INTEGER), @@ -1052,15 +1113,35 @@ class RuntimeServerTest ) ) ) - context.receiveN(1) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 1 + ) should contain theSameElementsAs Seq( context.executionComplete(contextId) ) context.consumeOut shouldEqual List("5") // pop the foo call context.send(Api.Request(requestId, Api.PopContextRequest(contextId))) - context.receiveN(3) should contain theSameElementsAs Seq( + context.receiveN(6) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PopContextResponse(contextId)), + TestMessages + .pending( + contextId, + fooX + ), + TestMessages + .update( + contextId, + mainFoo, + ConstantsGen.INTEGER, + fromCache = true + ), + TestMessages + .update( + contextId, + mainRes, + ConstantsGen.NOTHING + ), TestMessages .update( contextId, @@ -1128,7 +1209,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages .update( @@ -1174,7 +1257,9 @@ class RuntimeServerTest ) ) ) - context.receiveN(1) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 1 + ) should contain theSameElementsAs Seq( context.executionComplete(contextId) ) context.consumeOut shouldEqual List("6") @@ -1184,7 +1269,7 @@ class RuntimeServerTest val contextId = UUID.randomUUID() val requestId = UUID.randomUUID() val moduleName = "Enso_Test.Test.Main" - val idMain = context.Main.metadata.addItem(54, 47) + val idMain = context.Main.metadata.addItem(54, 47, "aaaaa") val contents = context.Main.code val mainFile = context.writeMain(contents) @@ -1214,7 +1299,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(6) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 6 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -1228,7 +1315,9 @@ class RuntimeServerTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item2)) ) - context.receiveN(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.fooY(contextId), context.Main.Update.fooZ(contextId), @@ -1237,8 +1326,22 @@ class RuntimeServerTest // pop foo call context.send(Api.Request(requestId, Api.PopContextRequest(contextId))) - context.receiveN(3) should contain theSameElementsAs Seq( + context.receiveN( + 6 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PopContextResponse(contextId)), + Api.Response( + None, + Api.ExpressionUpdates( + contextId, + Set( + context.Main.Update.pendingZ(), + context.Main.Update.pendingY() + ) + ) + ), + context.Main.Update.mainY(contextId, fromCache = true, noPointer = true), + TestMessages.update(contextId, idMain, ConstantsGen.INTEGER), context.Main.Update.mainY(contextId, fromCache = true), context.executionComplete(contextId) ) @@ -1256,9 +1359,9 @@ class RuntimeServerTest val moduleName = "Enso_Test.Test.Main" val metadata = new Metadata - val idResult = metadata.addItem(45, 4) - val idPrintln = metadata.addItem(54, 17) - val idMain = metadata.addItem(31, 40) + val idResult = metadata.addItem(45, 4, "aae") + val idPrintln = metadata.addItem(54, 17, "aaf") + val idMain = metadata.addItem(31, 40, "aaa") val code = """import Standard.Base.IO | @@ -1295,7 +1398,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, idResult, ConstantsGen.INTEGER), TestMessages.update(contextId, idPrintln, ConstantsGen.NOTHING), @@ -1319,8 +1424,13 @@ class RuntimeServerTest ) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveN( + 5 + ) should contain theSameElementsAs Seq( + TestMessages.pending(contextId, idResult), TestMessages.update(contextId, idResult, ConstantsGen.TEXT), + TestMessages.update(contextId, idPrintln, ConstantsGen.NOTHING), + TestMessages.update(contextId, idMain, ConstantsGen.NOTHING), context.executionComplete(contextId) ) context.consumeOut shouldEqual List("Hi") @@ -1332,17 +1442,17 @@ class RuntimeServerTest val moduleName = "Enso_Test.Test.Main" val metadata = new Metadata - val idMain = metadata.addItem(77, 35) - val idMainA = metadata.addItem(86, 8) - val idMainP = metadata.addItem(99, 12) + val idMain = metadata.addItem(77, 35, "aaaa") + val idMainA = metadata.addItem(86, 8, "aabb") + val idMainP = metadata.addItem(99, 12, "aacc") // pie id - metadata.addItem(119, 1) + metadata.addItem(119, 1, "eee") // uwu id - metadata.addItem(127, 1) + metadata.addItem(127, 1, "bbb") // hie id - metadata.addItem(135, 6) + metadata.addItem(135, 6, "fff") // Number.x id - metadata.addItem(155, 1) + metadata.addItem(155, 1, "999") val code = """from Standard.Base.Data.Numbers import Number |import Standard.Base.IO @@ -1385,7 +1495,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, idMainA, ConstantsGen.INTEGER), TestMessages.update(contextId, idMainP, ConstantsGen.NOTHING), @@ -1409,13 +1521,25 @@ class RuntimeServerTest ) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( TestMessages.update( contextId, idMainA, ConstantsGen.INTEGER, Api.MethodPointer(moduleName, ConstantsGen.NUMBER, "x") ), + TestMessages.update( + contextId, + idMainP, + ConstantsGen.NOTHING + ), + TestMessages.update( + contextId, + idMain, + ConstantsGen.NOTHING + ), context.executionComplete(contextId) ) context.consumeOut shouldEqual List("4") @@ -1435,7 +1559,9 @@ class RuntimeServerTest ) ) ) - context.receiveN(1) shouldEqual Seq(context.executionComplete(contextId)) + context.receiveNIgnoreExpressionUpdates(1) shouldEqual Seq( + context.executionComplete(contextId) + ) context.consumeOut shouldEqual List("5") // Edit s/1000.x 5/Main.pie/ @@ -1453,13 +1579,27 @@ class RuntimeServerTest ) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveN(5) should contain theSameElementsAs Seq( + TestMessages.pending( + contextId, + idMainA + ), TestMessages.update( contextId, idMainA, ConstantsGen.INTEGER, Api.MethodPointer(moduleName, "Enso_Test.Test.Main", "pie") ), + TestMessages.update( + contextId, + idMainP, + ConstantsGen.NOTHING + ), + TestMessages.update( + contextId, + idMain, + ConstantsGen.NOTHING + ), context.executionComplete(contextId) ) context.consumeOut shouldEqual List("3") @@ -1479,13 +1619,27 @@ class RuntimeServerTest ) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveN(5) should contain theSameElementsAs Seq( + TestMessages.pending( + contextId, + idMainA + ), TestMessages.update( contextId, idMainA, ConstantsGen.INTEGER, Api.MethodPointer(moduleName, "Enso_Test.Test.Main", "uwu") ), + TestMessages.update( + contextId, + idMainP, + ConstantsGen.NOTHING + ), + TestMessages.update( + contextId, + idMain, + ConstantsGen.NOTHING + ), context.executionComplete(contextId) ) context.consumeOut shouldEqual List("7") @@ -1505,13 +1659,27 @@ class RuntimeServerTest ) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveN(5) should contain theSameElementsAs Seq( + TestMessages.pending( + contextId, + idMainA + ), TestMessages.update( contextId, idMainA, ConstantsGen.TEXT, Api.MethodPointer(moduleName, "Enso_Test.Test.Main", "hie") ), + TestMessages.update( + contextId, + idMainP, + ConstantsGen.NOTHING + ), + TestMessages.update( + contextId, + idMain, + ConstantsGen.NOTHING + ), context.executionComplete(contextId) ) context.consumeOut shouldEqual List("hie!") @@ -1531,8 +1699,22 @@ class RuntimeServerTest ) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveN(5) should contain theSameElementsAs Seq( + TestMessages.pending( + contextId, + idMainA + ), TestMessages.update(contextId, idMainA, ConstantsGen.TEXT), + TestMessages.update( + contextId, + idMainP, + ConstantsGen.NOTHING + ), + TestMessages.update( + contextId, + idMain, + ConstantsGen.NOTHING + ), context.executionComplete(contextId) ) context.consumeOut shouldEqual List("Hello!") @@ -1544,10 +1726,10 @@ class RuntimeServerTest val moduleName = "Enso_Test.Test.Main" val metadata = new Metadata - val idMain = metadata.addItem(122, 88) - val id1 = metadata.addItem(131, 15) - val id2 = metadata.addItem(151, 18) - val id3 = metadata.addItem(174, 15) + val idMain = metadata.addItem(122, 88, "aaaa") + val id1 = metadata.addItem(131, 15, "aad1") + val id2 = metadata.addItem(151, 18, "aad2") + val id3 = metadata.addItem(174, 15, "aad3") // Note that Nothing.Nothing is on purpose. // If not provided the full name it will resolve the expression Nothing to a Nothing module. // Similarly Text.Text. That in turn will mismatch the expectations for method types which actually @@ -1595,7 +1777,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(6) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 6 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, idMain, ConstantsGen.NOTHING), TestMessages.update( @@ -1629,20 +1813,21 @@ class RuntimeServerTest ) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.executionComplete(contextId) ) // pop call1 context.send(Api.Request(requestId, Api.PopContextRequest(contextId))) - context.receiveN(5) should contain theSameElementsAs Seq( + context.receiveN(8) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PopContextResponse(contextId)), TestMessages.update( contextId, id1, ConstantsGen.INTEGER, - Api.MethodPointer(moduleName, ConstantsGen.NUMBER, "overloaded"), fromCache = true ), TestMessages.update( @@ -1657,6 +1842,18 @@ class RuntimeServerTest ConstantsGen.INTEGER, Api.MethodPointer(moduleName, ConstantsGen.NUMBER, "overloaded") ), + TestMessages.update( + contextId, + idMain, + ConstantsGen.NOTHING + ), + TestMessages.update( + contextId, + id1, + ConstantsGen.INTEGER, + Api.MethodPointer(moduleName, ConstantsGen.NUMBER, "overloaded"), + fromCache = true + ), context.executionComplete(contextId) ) @@ -1670,22 +1867,17 @@ class RuntimeServerTest ) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.executionComplete(contextId) ) // pop call2 context.send(Api.Request(requestId, Api.PopContextRequest(contextId))) - context.receiveN(5) should contain theSameElementsAs Seq( + context.receiveN(6) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PopContextResponse(contextId)), - TestMessages.update( - contextId, - id1, - ConstantsGen.INTEGER, - Api.MethodPointer(moduleName, ConstantsGen.NUMBER, "overloaded"), - fromCache = true - ), TestMessages.update( contextId, id2, @@ -1698,6 +1890,18 @@ class RuntimeServerTest ConstantsGen.INTEGER, Api.MethodPointer(moduleName, ConstantsGen.NUMBER, "overloaded") ), + TestMessages.update( + contextId, + idMain, + ConstantsGen.NOTHING + ), + TestMessages.update( + contextId, + id1, + ConstantsGen.INTEGER, + Api.MethodPointer(moduleName, ConstantsGen.NUMBER, "overloaded"), + fromCache = true + ), context.executionComplete(contextId) ) @@ -1711,22 +1915,17 @@ class RuntimeServerTest ) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.executionComplete(contextId) ) // pop call3 context.send(Api.Request(requestId, Api.PopContextRequest(contextId))) - context.receiveN(5) should contain theSameElementsAs Seq( + context.receiveN(6) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PopContextResponse(contextId)), - TestMessages.update( - contextId, - id1, - ConstantsGen.INTEGER, - Api.MethodPointer(moduleName, ConstantsGen.NUMBER, "overloaded"), - fromCache = true - ), TestMessages.update( contextId, id2, @@ -1739,6 +1938,18 @@ class RuntimeServerTest ConstantsGen.INTEGER, Api.MethodPointer(moduleName, ConstantsGen.NUMBER, "overloaded") ), + TestMessages.update( + contextId, + idMain, + ConstantsGen.NOTHING + ), + TestMessages.update( + contextId, + id1, + ConstantsGen.INTEGER, + Api.MethodPointer(moduleName, ConstantsGen.NUMBER, "overloaded"), + fromCache = true + ), context.executionComplete(contextId) ) } @@ -1788,7 +1999,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.update(contextId, xId, ConstantsGen.FUNCTION), TestMessages.update(contextId, mainRes, ConstantsGen.NOTHING), @@ -1835,7 +2048,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(2) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.executionComplete(contextId) ) @@ -1856,7 +2071,7 @@ class RuntimeServerTest ) ) ) - context.receive shouldEqual Some( + context.receiveNIgnoreExpressionUpdates(1) shouldEqual Seq( context.executionComplete(contextId) ) context.consumeOut shouldEqual List("I'm a modified!") @@ -1922,7 +2137,8 @@ class RuntimeServerTest ) ) ) - context.receive shouldEqual Some( + context.receiveN(2) shouldEqual Seq( + TestMessages.update(contextId, idMain, ConstantsGen.INTEGER), context.executionComplete(contextId) ) } @@ -1931,7 +2147,7 @@ class RuntimeServerTest val contextId = UUID.randomUUID() val requestId = UUID.randomUUID() val moduleName = "Enso_Test.Test.Main" - val idMain = context.Main.metadata.addItem(54, 47) + val idMain = context.Main.metadata.addItem(54, 47, "aaaa") val mainFile = context.writeMain(context.Main.code) @@ -1956,7 +2172,9 @@ class RuntimeServerTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(6) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 6 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -1970,7 +2188,9 @@ class RuntimeServerTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item2)) ) - context.receiveN(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.fooY(contextId), context.Main.Update.fooZ(contextId), @@ -1979,8 +2199,36 @@ class RuntimeServerTest // pop foo call context.send(Api.Request(requestId, Api.PopContextRequest(contextId))) - context.receiveN(3) should contain theSameElementsAs Seq( + context.receiveN( + 6 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PopContextResponse(contextId)), + Api.Response( + None, + Api.ExpressionUpdates( + contextId, + Set( + context.Main.Update.pendingZ(), + context.Main.Update.pendingY() + ) + ) + ), + context.Main.Update.mainY(contextId, fromCache = true, noPointer = true), + Api.Response( + Api.ExpressionUpdates( + contextId, + Set( + Api.ExpressionUpdate( + idMain, + Some(ConstantsGen.INTEGER), + None, + Vector(Api.ProfilingInfo.ExecutionTime(0)), + false, + Api.ExpressionUpdate.Payload.Value() + ) + ) + ) + ), context.Main.Update.mainY(contextId, fromCache = true), context.executionComplete(contextId) ) @@ -2039,7 +2287,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(2) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.executionComplete(contextId) ) @@ -2073,7 +2323,9 @@ class RuntimeServerTest ) ) ) - context.receiveN(1) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 1 + ) should contain theSameElementsAs Seq( context.executionComplete(contextId) ) context.consumeOut shouldEqual List("I'm a modified!") @@ -2112,7 +2364,9 @@ class RuntimeServerTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -2124,7 +2378,9 @@ class RuntimeServerTest context.send( Api.Request(requestId, Api.RecomputeContextRequest(contextId, None)) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.RecomputeContextResponse(contextId)), context.executionComplete(contextId) ) @@ -2158,7 +2414,9 @@ class RuntimeServerTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -2176,7 +2434,9 @@ class RuntimeServerTest ) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.RecomputeContextResponse(contextId)), context.executionComplete(contextId) ) @@ -2210,7 +2470,9 @@ class RuntimeServerTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -2230,7 +2492,9 @@ class RuntimeServerTest ) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.RecomputeContextResponse(contextId)), context.executionComplete(contextId) ) @@ -2268,7 +2532,9 @@ class RuntimeServerTest ) ) ) - context.receiveN(3) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.ExecutionFailed( @@ -2316,7 +2582,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.ExecutionFailed( @@ -2367,7 +2635,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.ExecutionFailed( @@ -2421,7 +2691,9 @@ class RuntimeServerTest ) ) ) - context.receiveN(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.ExecutionUpdate( @@ -2489,7 +2761,9 @@ class RuntimeServerTest ) ) ) - context.receiveN(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.ExecutionUpdate( @@ -2565,7 +2839,9 @@ class RuntimeServerTest ) ) ) - context.receiveN(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.ExecutionUpdate( @@ -2643,7 +2919,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.ExecutionUpdate( @@ -2721,7 +2999,9 @@ class RuntimeServerTest ) ) ) - context.receiveN(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.ExecutionUpdate( @@ -2814,7 +3094,9 @@ class RuntimeServerTest ) ) ) - context.receiveN(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.ExecutionUpdate( @@ -2873,7 +3155,9 @@ class RuntimeServerTest ) ) ) - context.receiveN(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.ExecutionUpdate( @@ -2996,7 +3280,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.ExecutionUpdate( @@ -3063,7 +3349,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(2) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.ExecutionUpdate( @@ -3123,7 +3411,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(2) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.ExecutionUpdate( @@ -3167,7 +3457,9 @@ class RuntimeServerTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main2.Update.mainY(contextId), context.Main2.Update.mainZ(contextId), @@ -3179,7 +3471,9 @@ class RuntimeServerTest context.send( Api.Request(requestId, Api.RecomputeContextRequest(contextId, None)) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.RecomputeContextResponse(contextId)), context.executionComplete(contextId) ) @@ -3224,7 +3518,9 @@ class RuntimeServerTest ) ) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -3245,7 +3541,9 @@ class RuntimeServerTest context.send( Api.Request(requestId, Api.RecomputeContextRequest(contextId, None)) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.RecomputeContextResponse(contextId)), context.executionComplete(contextId) ) @@ -3260,14 +3558,18 @@ class RuntimeServerTest ) ) ) - context.receiveN(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.RecomputeContextResponse(contextId)), + context.Main.Update.mainX(contextId), TestMessages.update( contextId, context.Main.idMainY, ConstantsGen.INTEGER, Api.MethodPointer("Enso_Test.Foo.Main", ConstantsGen.NUMBER, "foo") ), + context.Main.Update.mainZ(contextId), context.executionComplete(contextId) ) } diff --git a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeSuggestionUpdatesTest.scala b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeSuggestionUpdatesTest.scala index 7132ac3171dd..72bc40948ff8 100644 --- a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeSuggestionUpdatesTest.scala +++ b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeSuggestionUpdatesTest.scala @@ -137,7 +137,9 @@ class RuntimeSuggestionUpdatesTest ) ) ) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.SuggestionsDatabaseModuleUpdateNotification( @@ -199,7 +201,9 @@ class RuntimeSuggestionUpdatesTest ) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response( Api.SuggestionsDatabaseModuleUpdateNotification( module = moduleName, @@ -276,7 +280,9 @@ class RuntimeSuggestionUpdatesTest ) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response( Api.SuggestionsDatabaseModuleUpdateNotification( module = moduleName, @@ -373,7 +379,9 @@ class RuntimeSuggestionUpdatesTest ) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response( Api.SuggestionsDatabaseModuleUpdateNotification( module = moduleName, @@ -479,7 +487,9 @@ class RuntimeSuggestionUpdatesTest ) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response( Api.SuggestionsDatabaseModuleUpdateNotification( module = moduleName, @@ -614,7 +624,9 @@ class RuntimeSuggestionUpdatesTest ) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response( Api.SuggestionsDatabaseModuleUpdateNotification( module = moduleName, @@ -738,7 +750,9 @@ class RuntimeSuggestionUpdatesTest ) ) ) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.SuggestionsDatabaseModuleUpdateNotification( @@ -917,7 +931,9 @@ class RuntimeSuggestionUpdatesTest ) ) ) - context.receiveNIgnoreStdLib(4) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), Api.Response( Api.SuggestionsDatabaseModuleUpdateNotification( @@ -1105,7 +1121,9 @@ class RuntimeSuggestionUpdatesTest ) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response( Api.SuggestionsDatabaseModuleUpdateNotification( module = moduleName, @@ -1152,7 +1170,9 @@ class RuntimeSuggestionUpdatesTest ) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response( Api.SuggestionsDatabaseModuleUpdateNotification( module = moduleName, diff --git a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeVisualizationsTest.scala b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeVisualizationsTest.scala index d57b528044d9..ab49a05fee7a 100644 --- a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeVisualizationsTest.scala +++ b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeVisualizationsTest.scala @@ -321,7 +321,9 @@ class RuntimeVisualizationsTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(6) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 6 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -347,7 +349,8 @@ class RuntimeVisualizationsTest ) ) ) - val attachVisualisationResponses = context.receiveN(3) + val attachVisualisationResponses = + context.receiveNIgnoreExpressionUpdates(3) attachVisualisationResponses should contain allOf ( Api.Response(requestId, Api.VisualisationAttached()), context.executionComplete(contextId) @@ -373,7 +376,7 @@ class RuntimeVisualizationsTest Api.Request(requestId, Api.RecomputeContextRequest(contextId, None)) ) - val recomputeResponses = context.receiveN(3) + val recomputeResponses = context.receiveNIgnoreExpressionUpdates(3) recomputeResponses should contain allOf ( Api.Response(requestId, Api.RecomputeContextResponse(contextId)), context.executionComplete(contextId) @@ -436,7 +439,9 @@ class RuntimeVisualizationsTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -486,7 +491,7 @@ class RuntimeVisualizationsTest context.send( Api.Request(requestId, Api.RecomputeContextRequest(contextId, None)) ) - context.receiveN(2) should contain allOf ( + context.receiveNIgnoreExpressionUpdates(2) should contain allOf ( Api.Response(requestId, Api.RecomputeContextResponse(contextId)), context.executionComplete(contextId) ) @@ -503,7 +508,7 @@ class RuntimeVisualizationsTest ) ) ) - val recomputeResponses2 = context.receiveN(3) + val recomputeResponses2 = context.receiveNIgnoreExpressionUpdates(3) recomputeResponses2 should contain allOf ( Api.Response(requestId, Api.RecomputeContextResponse(contextId)), context.executionComplete(contextId) @@ -567,7 +572,10 @@ class RuntimeVisualizationsTest Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + System.out.println("Begin check") + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -629,7 +637,7 @@ class RuntimeVisualizationsTest ) ) - val editFileResponse = context.receiveN(2) + val editFileResponse = context.receiveNIgnoreExpressionUpdates(2) editFileResponse should contain( context.executionComplete(contextId) ) @@ -692,7 +700,9 @@ class RuntimeVisualizationsTest Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -754,7 +764,7 @@ class RuntimeVisualizationsTest ) ) - val editFileResponse = context.receiveN(2) + val editFileResponse = context.receiveNIgnoreExpressionUpdates(2) editFileResponse should contain( context.executionComplete(contextId) ) @@ -815,7 +825,9 @@ class RuntimeVisualizationsTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -967,7 +979,7 @@ class RuntimeVisualizationsTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - val pushResponses = context.receiveNIgnoreStdLib(6) + val pushResponses = context.receiveNIgnorePendingExpressionUpdates(6) pushResponses should contain allOf ( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), @@ -1012,7 +1024,9 @@ class RuntimeVisualizationsTest context.send( Api.Request(requestId, Api.RecomputeContextRequest(contextId, None)) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.RecomputeContextResponse(contextId)), context.executionComplete(contextId) ) @@ -1029,7 +1043,9 @@ class RuntimeVisualizationsTest ) ) ) - context.receiveN(2) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 2 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.RecomputeContextResponse(contextId)), context.executionComplete(contextId) ) @@ -1077,7 +1093,9 @@ class RuntimeVisualizationsTest Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -1139,7 +1157,9 @@ class RuntimeVisualizationsTest ) ) - context.receiveN(1) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 1 + ) should contain theSameElementsAs Seq( context.executionComplete(contextId) ) } @@ -1184,7 +1204,9 @@ class RuntimeVisualizationsTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(5) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 5 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -1312,7 +1334,9 @@ class RuntimeVisualizationsTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(6) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 6 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -1374,7 +1398,9 @@ class RuntimeVisualizationsTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(6) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 6 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -1401,7 +1427,7 @@ class RuntimeVisualizationsTest ) ) - val attachVisualisationResponses = context.receiveN(4) + val attachVisualisationResponses = context.receiveN(6) attachVisualisationResponses should contain allOf ( Api.Response(requestId, Api.VisualisationAttached()), context.executionComplete(contextId) @@ -1424,10 +1450,14 @@ class RuntimeVisualizationsTest data.sameElements("(Builtin 'JSON')".getBytes) shouldBe true - val loadedLibraries = attachVisualisationResponses.collect { - case Api.Response(None, Api.LibraryLoaded(namespace, name, _, _)) => - (namespace, name) - } + val loadedLibraries = attachVisualisationResponses + .collect { + case Api.Response(None, Api.LibraryLoaded(namespace, name, _, _)) => + Some((namespace, name)) + case _ => None + } + .filter(_.isDefined) + .flatten loadedLibraries should contain(("Standard", "Visualization")) } @@ -1463,7 +1493,9 @@ class RuntimeVisualizationsTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(6) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 6 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -1539,7 +1571,9 @@ class RuntimeVisualizationsTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(6) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 6 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -1565,7 +1599,9 @@ class RuntimeVisualizationsTest ) ) ) - context.receiveN(3) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.VisualisationAttached()), Api.Response( Api.VisualisationEvaluationFailed( @@ -1646,7 +1682,9 @@ class RuntimeVisualizationsTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(6) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 6 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -1672,7 +1710,9 @@ class RuntimeVisualizationsTest ) ) ) - context.receiveN(3) should contain theSameElementsAs Seq( + context.receiveNIgnoreExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.VisualisationAttached()), Api.Response( Api.VisualisationEvaluationFailed( @@ -1751,7 +1791,7 @@ class RuntimeVisualizationsTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - val responses = context.receiveN(n = 4, timeoutSeconds = 60) + val responses = context.receiveN(n = 5, timeoutSeconds = 60) responses should contain allOf ( Api.Response(requestId, Api.PushContextResponse(contextId)), @@ -1786,7 +1826,7 @@ class RuntimeVisualizationsTest ) ) ) - val attachVisualisationResponses = context.receiveN(3) + val attachVisualisationResponses = context.receiveN(5) attachVisualisationResponses should contain allOf ( Api.Response(requestId, Api.VisualisationAttached()), context.executionComplete(contextId) @@ -1847,7 +1887,9 @@ class RuntimeVisualizationsTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(3) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 3 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.panic( contextId, @@ -1874,7 +1916,9 @@ class RuntimeVisualizationsTest ) ) ) - context.receiveN(4) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 4 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.VisualisationAttached()), TestMessages.panic( contextId, @@ -1957,7 +2001,7 @@ class RuntimeVisualizationsTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - val pushContextResponses = context.receiveNIgnoreStdLib(3) + val pushContextResponses = context.receiveNIgnorePendingExpressionUpdates(3) pushContextResponses should contain allOf ( Api.Response(requestId, Api.PushContextResponse(contextId)), TestMessages.error( @@ -1989,7 +2033,8 @@ class RuntimeVisualizationsTest ) ) ) - val attachVisualisationResponses = context.receiveN(3) + val attachVisualisationResponses = + context.receiveNIgnoreExpressionUpdates(3) attachVisualisationResponses should contain allOf ( Api.Response(requestId, Api.VisualisationAttached()), context.executionComplete(contextId) @@ -2053,7 +2098,9 @@ class RuntimeVisualizationsTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(6) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 6 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -2083,7 +2130,8 @@ class RuntimeVisualizationsTest ) ) ) - val attachVisualisationResponses = context.receiveN(3) + val attachVisualisationResponses = + context.receiveNIgnoreExpressionUpdates(3) attachVisualisationResponses should contain allOf ( Api.Response(requestId, Api.VisualisationAttached()), context.executionComplete(contextId) @@ -2109,7 +2157,7 @@ class RuntimeVisualizationsTest Api.Request(requestId, Api.RecomputeContextRequest(contextId, None)) ) - val recomputeResponses = context.receiveN(3) + val recomputeResponses = context.receiveNIgnoreExpressionUpdates(3) recomputeResponses should contain allOf ( Api.Response(requestId, Api.RecomputeContextResponse(contextId)), context.executionComplete(contextId) @@ -2176,7 +2224,9 @@ class RuntimeVisualizationsTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(6) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 6 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -2207,7 +2257,8 @@ class RuntimeVisualizationsTest ) ) ) - val attachVisualisationResponses = context.receiveN(3) + val attachVisualisationResponses = + context.receiveNIgnoreExpressionUpdates(3) attachVisualisationResponses should contain allOf ( Api.Response(requestId, Api.VisualisationAttached()), context.executionComplete(contextId) @@ -2234,7 +2285,7 @@ class RuntimeVisualizationsTest Api.Request(requestId, Api.RecomputeContextRequest(contextId, None)) ) - val recomputeResponses = context.receiveN(3) + val recomputeResponses = context.receiveNIgnoreExpressionUpdates(3) recomputeResponses should contain allOf ( Api.Response(requestId, Api.RecomputeContextResponse(contextId)), context.executionComplete(contextId) @@ -2276,7 +2327,8 @@ class RuntimeVisualizationsTest ) ) ) - val modifyVisualisationResponses = context.receiveN(2) + val modifyVisualisationResponses = + context.receiveNIgnoreExpressionUpdates(2) modifyVisualisationResponses should contain( Api.Response(requestId, Api.VisualisationModified()) ) @@ -2344,7 +2396,9 @@ class RuntimeVisualizationsTest context.send( Api.Request(requestId, Api.PushContextRequest(contextId, item1)) ) - context.receiveNIgnoreStdLib(6) should contain theSameElementsAs Seq( + context.receiveNIgnorePendingExpressionUpdates( + 6 + ) should contain theSameElementsAs Seq( Api.Response(requestId, Api.PushContextResponse(contextId)), context.Main.Update.mainX(contextId), context.Main.Update.mainY(contextId), @@ -2375,7 +2429,8 @@ class RuntimeVisualizationsTest ) ) ) - val attachVisualisationResponses = context.receiveN(3) + val attachVisualisationResponses = + context.receiveNIgnoreExpressionUpdates(3) attachVisualisationResponses should contain allOf ( Api.Response(requestId, Api.VisualisationAttached()), context.executionComplete(contextId) @@ -2402,7 +2457,7 @@ class RuntimeVisualizationsTest Api.Request(requestId, Api.RecomputeContextRequest(contextId, None)) ) - val recomputeResponses = context.receiveN(3) + val recomputeResponses = context.receiveNIgnoreExpressionUpdates(3) recomputeResponses should contain allOf ( Api.Response(requestId, Api.RecomputeContextResponse(contextId)), context.executionComplete(contextId) @@ -2440,7 +2495,7 @@ class RuntimeVisualizationsTest ) ) - val editFileResponse = context.receiveN(2) + val editFileResponse = context.receiveNIgnoreExpressionUpdates(2) editFileResponse should contain( context.executionComplete(contextId) ) diff --git a/engine/runtime/src/main/scala/org/enso/interpreter/instrument/command/RecomputeContextCmd.scala b/engine/runtime/src/main/scala/org/enso/interpreter/instrument/command/RecomputeContextCmd.scala index 7402c997477b..782cdfdede66 100644 --- a/engine/runtime/src/main/scala/org/enso/interpreter/instrument/command/RecomputeContextCmd.scala +++ b/engine/runtime/src/main/scala/org/enso/interpreter/instrument/command/RecomputeContextCmd.scala @@ -43,7 +43,10 @@ class RecomputeContextCmd( val cacheInvalidationCommands = request.expressions.toSeq .map(CacheInvalidation.Command(_)) .map(CacheInvalidation(CacheInvalidation.StackSelector.Top, _)) - CacheInvalidation.runAll(stack, cacheInvalidationCommands) + CacheInvalidation.runAll( + stack, + cacheInvalidationCommands + ) reply(Api.RecomputeContextResponse(request.contextId)) true } diff --git a/engine/runtime/src/main/scala/org/enso/interpreter/instrument/job/ProgramExecutionSupport.scala b/engine/runtime/src/main/scala/org/enso/interpreter/instrument/job/ProgramExecutionSupport.scala index b50dfe88fce5..091a2f735f73 100644 --- a/engine/runtime/src/main/scala/org/enso/interpreter/instrument/job/ProgramExecutionSupport.scala +++ b/engine/runtime/src/main/scala/org/enso/interpreter/instrument/job/ProgramExecutionSupport.scala @@ -95,12 +95,43 @@ object ProgramExecutionSupport { enterables += fun.getExpressionId -> fun.getCall } + def notifyPendingCacheItems(cache: RuntimeCache): Unit = { + val knownKeys = cache.getWeights.entrySet + val cachedKeys = cache.getKeys + val pendingKeys = new collection.mutable.HashSet[UUID]() + + knownKeys.forEach { e => + if (e.getValue > 0) { + if (!cachedKeys.contains(e.getKey)) { + pendingKeys.add(e.getKey) + } + } + } + if (pendingKeys.nonEmpty) { + val ids = pendingKeys.map { key => + Api.ExpressionUpdate( + key, + None, + None, + Vector.empty, + true, + Api.ExpressionUpdate.Payload.Pending(None, None) + ) + } + val msg = Api.Response( + Api.ExpressionUpdates(contextId, ids.toSet) + ) + ctx.endpoint.sendToClient(msg) + } + } + executionFrame match { case ExecutionFrame( ExecutionItem.Method(module, cons, function), cache, syncState ) => + notifyPendingCacheItems(cache) ctx.executionService.execute( module.toString, cons.item, @@ -125,6 +156,7 @@ object ProgramExecutionSupport { .orElseThrow(() => new ModuleNotFoundForExpressionIdException(expressionId) ) + notifyPendingCacheItems(cache) ctx.executionService.execute( module, callData, diff --git a/engine/runtime/src/test/scala/org/enso/interpreter/test/Metadata.scala b/engine/runtime/src/test/scala/org/enso/interpreter/test/Metadata.scala index fb3c3db791c5..a9c3b577ba2b 100644 --- a/engine/runtime/src/test/scala/org/enso/interpreter/test/Metadata.scala +++ b/engine/runtime/src/test/scala/org/enso/interpreter/test/Metadata.scala @@ -17,10 +17,16 @@ class Metadata { * * @param start the start position of the entry. * @param len the length of the entry. + * @param suggestion optional hexadecimal suggestion of UUID prefix * @return the new entry's id. */ - def addItem(start: Int, len: Int): UUID = { - val id = UUID.randomUUID(); + def addItem(start: Int, len: Int, suggestion: String = null): UUID = { + var id = UUID.randomUUID(); + if (suggestion != null) { + val lo = java.lang.Long.parseUnsignedLong(suggestion, 16); + val hi = id.getMostSignificantBits(); + id = new UUID(lo, hi) + } items ::= Item(start, len, id) id } diff --git a/engine/runtime/src/test/scala/org/enso/interpreter/test/instrument/InstrumentTestContext.scala b/engine/runtime/src/test/scala/org/enso/interpreter/test/instrument/InstrumentTestContext.scala index 509a105fd8db..43506a58a5ad 100644 --- a/engine/runtime/src/test/scala/org/enso/interpreter/test/instrument/InstrumentTestContext.scala +++ b/engine/runtime/src/test/scala/org/enso/interpreter/test/instrument/InstrumentTestContext.scala @@ -28,14 +28,61 @@ class InstrumentTestContext { .toList } + def receiveNIgnoreExpressionUpdates( + n: Int, + timeoutSeconds: Long = 60 + ): List[Api.Response] = { + receiveNWithFilter( + n, + { + case Some(Api.Response(None, Api.ExpressionUpdates(_, _))) => false + case _ => true + }, + timeoutSeconds + ) + } + + def receiveNIgnorePendingExpressionUpdates( + n: Int, + timeoutSeconds: Long = 60, + updatesOnlyFor: Set[Api.ExpressionId] = Set() + ): List[Api.Response] = { + receiveNWithFilter( + n, + { + case Some(Api.Response(None, Api.ExpressionUpdates(_, updates))) => + updates.find { u => + u.payload match { + case _: Api.ExpressionUpdate.Payload.Pending => false + case _ => + updatesOnlyFor.isEmpty || updatesOnlyFor.contains( + u.expressionId + ) + } + }.isDefined + case _ => true + }, + timeoutSeconds + ) + } + def receiveNIgnoreStdLib( n: Int, timeoutSeconds: Long = 60 + ): List[Api.Response] = { + receiveNWithFilter(n, (_ => true), timeoutSeconds) + } + + private def receiveNWithFilter( + n: Int, + f: (Any => Boolean), + timeoutSeconds: Long ): List[Api.Response] = { var count: Int = n var lastSeen: Option[Api.Response] = None Iterator .continually(receiveWithTimeout(timeoutSeconds)) + .filter(f) .takeWhile { case Some(Api.Response(None, Api.LibraryLoaded(_, _, _, _))) => count > 0 diff --git a/engine/runtime/src/test/scala/org/enso/interpreter/test/instrument/TestMessages.scala b/engine/runtime/src/test/scala/org/enso/interpreter/test/instrument/TestMessages.scala index 1b7a4a4a13d2..4393d947e990 100644 --- a/engine/runtime/src/test/scala/org/enso/interpreter/test/instrument/TestMessages.scala +++ b/engine/runtime/src/test/scala/org/enso/interpreter/test/instrument/TestMessages.scala @@ -39,12 +39,14 @@ object TestMessages { * @param contextId an identifier of the context * @param expressionId an identifier of the expression * @param expressionType a type of the expression + * @param fromCache whether or not the value for this expression came * @return the expression update response */ def update( contextId: UUID, expressionId: UUID, - expressionType: String + expressionType: String, + fromCache: Boolean = false ): Api.Response = Api.Response( Api.ExpressionUpdates( @@ -55,7 +57,7 @@ object TestMessages { Some(expressionType), None, Vector(Api.ProfilingInfo.ExecutionTime(0)), - false, + fromCache, Api.ExpressionUpdate.Payload.Value() ) ) @@ -271,4 +273,34 @@ object TestMessages { ) ) + /** Create an pending response. + * + * @param contextId an identifier of the context + * @param expressionId an identifier of the expression + * @param expressionType a type of the expression + * @param methodPointer a pointer to the method definition + * @param fromCache whether or not the value for this expression came + * from the cache + * @return the expression update response + */ + def pending( + contextId: UUID, + expressionId: UUID + ): Api.Response = + Api.Response( + Api.ExpressionUpdates( + contextId, + Set( + Api.ExpressionUpdate( + expressionId, + None, + None, + Vector(), + true, + Api.ExpressionUpdate.Payload.Pending(None, None) + ) + ) + ) + ) + }