@@ -2095,14 +2095,16 @@ defmodule Livebook.SessionTest do
2095
2095
2096
2096
describe "code evaluation logging" do
2097
2097
test "logs code evaluation for regular sessions" do
2098
- session = start_session ( )
2099
- Session . subscribe ( session . id )
2100
-
2101
- { _section_id , cell_id } = insert_section_and_cell ( session . pid )
2102
-
2103
2098
unique_id = Utils . random_short_id ( )
2104
2099
# Use random ID to uniquely identify the source code of this cell
2105
- Session . set_cell_attributes ( session . pid , cell_id , % { source: "#{ unique_id } " } )
2100
+ code_cell = % { Notebook.Cell . new ( :code ) | source: ~s/ "#{ unique_id } "/ }
2101
+ section = % { Notebook.Section . new ( ) | cells: [ code_cell ] }
2102
+ notebook = % { Notebook . new ( ) | sections: [ section ] }
2103
+
2104
+ session = start_session ( notebook: notebook )
2105
+ Session . subscribe ( session . id )
2106
+
2107
+ cell_id = code_cell . id
2106
2108
2107
2109
log =
2108
2110
capture_log ( [ level: :info , metadata: [ :session_mode , :code , :event ] ] , fn ->
@@ -2111,48 +2113,41 @@ defmodule Livebook.SessionTest do
2111
2113
end )
2112
2114
2113
2115
# Logs from other test might be captured, so we're using an unique_id
2114
- assert log =~ " code=#{ unique_id } "
2116
+ assert log =~ ~s / code=" #{ unique_id } "/
2115
2117
assert log =~ "Evaluating code"
2116
2118
assert log =~ "session_mode=default"
2117
2119
assert log =~ "event=code.evaluate"
2118
2120
end
2119
2121
2120
2122
test "logs code evaluation for preview apps" do
2121
- session = start_session ( )
2122
- Session . subscribe ( session . id )
2123
-
2124
2123
slug = Utils . random_short_id ( )
2125
2124
app_settings = % { Notebook.AppSettings . new ( ) | slug: slug }
2126
- Session . set_app_settings ( session . pid , app_settings )
2127
-
2128
- { section_id , _cell_id } = insert_section_and_cell ( session . pid )
2129
-
2130
- Apps . subscribe ( )
2131
- Session . deploy_app ( session . pid )
2132
- assert_receive { :app_created , % { slug: ^ slug , pid: app_pid } }
2133
-
2134
- on_exit ( fn ->
2135
- App . close ( app_pid )
2136
- end )
2137
-
2138
- session_id = App . get_session_id ( app_pid )
2139
- { :ok , app_session } = Livebook.Sessions . fetch_session ( session_id )
2140
-
2141
- Session . subscribe ( app_session . id )
2142
2125
2143
2126
unique_id = Utils . random_short_id ( )
2144
2127
# Use random ID to uniquely identify the source code of this cell
2145
- Session . insert_cell ( app_session . pid , section_id , 0 , :code , % { source: "#{ unique_id } " } )
2146
- assert_receive { :operation , { :insert_cell , _ , ^ section_id , 0 , :code , cell_id , _ } }
2128
+ code_cell = % { Notebook.Cell . new ( :code ) | source: ~s/ "#{ unique_id } "/ }
2129
+ section = % { Notebook.Section . new ( ) | cells: [ code_cell ] }
2130
+ notebook = % { Notebook . new ( ) | sections: [ section ] , app_settings: app_settings }
2131
+
2132
+ session = start_session ( notebook: notebook )
2133
+ Session . subscribe ( session . id )
2147
2134
2148
2135
log =
2149
2136
capture_log ( [ level: :info , metadata: [ :session_mode , :code , :event ] ] , fn ->
2150
- Session . queue_cell_evaluation ( app_session . pid , cell_id )
2151
- assert_receive { :operation , { :add_cell_evaluation_response , _ , ^ cell_id , _ , _ } }
2137
+ Apps . subscribe ( )
2138
+ Session . deploy_app ( session . pid )
2139
+ assert_receive { :app_created , % { slug: ^ slug , pid: app_pid } }
2140
+
2141
+ on_exit ( fn ->
2142
+ App . close ( app_pid )
2143
+ end )
2144
+
2145
+ assert_receive { :app_updated ,
2146
+ % { pid: ^ app_pid , sessions: [ % { app_status: % { execution: :executed } } ] } }
2152
2147
end )
2153
2148
2154
2149
# Logs from other test might be captured, so we're using an unique_id
2155
- assert log =~ " code=#{ unique_id } "
2150
+ assert log =~ ~s / code=" #{ unique_id } "/
2156
2151
assert log =~ "Evaluating code"
2157
2152
assert log =~ "session_mode=app"
2158
2153
assert log =~ "event=code.evaluate"
@@ -2164,22 +2159,18 @@ defmodule Livebook.SessionTest do
2164
2159
2165
2160
unique_id = Utils . random_short_id ( )
2166
2161
# Use random ID to uniquely identify the source code of this cell
2167
- code_cell = % { Notebook.Cell . new ( :code ) | source: "#{ unique_id } " }
2162
+ code_cell = % { Notebook.Cell . new ( :code ) | source: ~s / "#{ unique_id } "/ }
2168
2163
section = % { Notebook.Section . new ( ) | cells: [ code_cell ] }
2169
2164
notebook = % { Notebook . new ( ) | sections: [ section ] , app_settings: app_settings }
2170
2165
2171
- app_pid = deploy_notebook_sync ( notebook , permanent: true )
2172
- session_id = App . get_session_id ( app_pid )
2173
-
2174
- { :ok , app_session } = Livebook.Sessions . fetch_session ( session_id )
2175
-
2176
- Session . subscribe ( app_session . id )
2177
- cell_id = code_cell . id
2178
-
2179
2166
log =
2180
2167
capture_log ( [ level: :info , metadata: [ :session_mode , :code , :event ] ] , fn ->
2181
- Session . queue_cell_evaluation ( app_session . pid , cell_id )
2182
- assert_receive { :operation , { :add_cell_evaluation_response , _ , ^ cell_id , _ , _ } }
2168
+ Apps . subscribe ( )
2169
+
2170
+ app_pid = deploy_notebook_sync ( notebook , permanent: true )
2171
+
2172
+ assert_receive { :app_updated ,
2173
+ % { pid: ^ app_pid , sessions: [ % { app_status: % { execution: :executed } } ] } }
2183
2174
end )
2184
2175
2185
2176
# Logs from other test might be captured, so we're using an unique_id
0 commit comments