@@ -207,4 +207,113 @@ describe('Test operations involving meta data', () => {
207207 expect ( sample . get ( 'my_string' ) ) . to . deep . equals ( testJsonObject . my_string )
208208 }
209209 } )
210- } )
210+
211+ it ( 'test getting sample_state' , async ( ) => {
212+ testOutput . write ( )
213+ try {
214+ await testInput . wait ( testExpectSuccessTimeout )
215+ } catch ( err ) {
216+ // Fail the test
217+ console . log ( 'Error caught: ' + err )
218+ expect ( false ) . to . deep . equals ( true )
219+ }
220+
221+ // Since this is the first time that we are accessing the sample, it should
222+ // have a sample state of NOT_READ
223+ testInput . read ( )
224+ expect ( testInput . samples . get ( 0 ) . info . get ( 'sample_state' ) ) . to . deep . equals ( 'NOT_READ' )
225+ // Now that we have already accessed the sample once time, accessing it
226+ // again should result in a sample state of READ
227+ testInput . read ( )
228+ expect ( testInput . samples . get ( 0 ) . info . get ( 'sample_state' ) ) . to . deep . equals ( 'READ' )
229+ // Taking after a read should also have a sample state of READ
230+ testInput . take ( )
231+ expect ( testInput . samples . get ( 0 ) . info . get ( 'sample_state' ) ) . to . deep . equals ( 'READ' )
232+ } )
233+
234+ it ( 'test getting instance state' , async ( ) => {
235+ testOutput . write ( )
236+ try {
237+ await testInput . wait ( testExpectSuccessTimeout )
238+ } catch ( err ) {
239+ // Fail the test
240+ console . log ( 'Error caught: ' + err )
241+ expect ( false ) . to . deep . equals ( true )
242+ }
243+ testInput . take ( )
244+ // Instance is currently alive
245+ expect ( testInput . samples . get ( 0 ) . info . get ( 'instance_state' ) ) . to . deep . equals ( 'ALIVE' )
246+ // Disposing the sample should update the instance state
247+ testOutput . write ( { action : 'dispose' } )
248+ try {
249+ await testInput . wait ( testExpectSuccessTimeout )
250+ } catch ( err ) {
251+ // Fail the test
252+ console . log ( 'Error caught: ' + err )
253+ expect ( false ) . to . deep . equals ( true )
254+ }
255+ testInput . take ( )
256+ expect ( testInput . samples . get ( 0 ) . info . get ( 'instance_state' ) ) . to . deep . equals ( 'NOT_ALIVE_DISPOSED' )
257+ // Writing the sample again should transition it back to alive
258+ testOutput . write ( )
259+ try {
260+ await testInput . wait ( testExpectSuccessTimeout )
261+ } catch ( err ) {
262+ // Fail the test
263+ console . log ( 'Error caught: ' + err )
264+ expect ( false ) . to . deep . equals ( true )
265+ }
266+ testInput . take ( )
267+ // Instance is currently alive
268+ expect ( testInput . samples . get ( 0 ) . info . get ( 'instance_state' ) ) . to . deep . equals ( 'ALIVE' )
269+ // Unregister the instance to get NO_WRITERS
270+ testOutput . write ( { action : 'unregister' } )
271+ try {
272+ await testInput . wait ( testExpectSuccessTimeout )
273+ } catch ( err ) {
274+ // Fail the test
275+ console . log ( 'Error caught: ' + err )
276+ expect ( false ) . to . deep . equals ( true )
277+ }
278+ testInput . take ( )
279+ expect ( testInput . samples . get ( 0 ) . info . get ( 'instance_state' ) ) . to . deep . equals ( 'NOT_ALIVE_NO_WRITERS' )
280+ } )
281+
282+ it ( 'test getting sample view state' , async ( ) => {
283+ // View state is per-instance
284+ testOutput . instance . setString ( 'my_key_string' , 'Brown' )
285+ testOutput . write ( )
286+ try {
287+ await testInput . wait ( testExpectSuccessTimeout )
288+ } catch ( err ) {
289+ // Fail the test
290+ console . log ( 'Error caught: ' + err )
291+ expect ( false ) . to . deep . equals ( true )
292+ }
293+ testInput . take ( )
294+ expect ( testInput . samples . get ( 0 ) . info . get ( 'view_state' ) ) . to . deep . equals ( 'NEW' )
295+ // Updating that instance should update the view state
296+ testOutput . write ( )
297+ try {
298+ await testInput . wait ( testExpectSuccessTimeout )
299+ } catch ( err ) {
300+ // Fail the test
301+ console . log ( 'Error caught: ' + err )
302+ expect ( false ) . to . deep . equals ( true )
303+ }
304+ testInput . take ( )
305+ expect ( testInput . samples . get ( 0 ) . info . get ( 'view_state' ) ) . to . deep . equals ( 'NOT_NEW' )
306+ // Writing a new instance should have a NEW view state
307+ testOutput . instance . setString ( 'my_key_string' , 'Maroon' )
308+ testOutput . write ( )
309+ try {
310+ await testInput . wait ( testExpectSuccessTimeout )
311+ } catch ( err ) {
312+ // Fail the test
313+ console . log ( 'Error caught: ' + err )
314+ expect ( false ) . to . deep . equals ( true )
315+ }
316+ testInput . take ( )
317+ expect ( testInput . samples . get ( 0 ) . info . get ( 'view_state' ) ) . to . deep . equals ( 'NEW' )
318+ } )
319+ } )
0 commit comments