Răsfoiți Sursa

Added more advanced tests.

Maciej Bukowski 6 ani în urmă
părinte
comite
db9249f007

+ 0 - 9
packages/ckeditor5-watchdog/src/contextwatchdog.js

@@ -412,15 +412,6 @@ class ActionQueue {
 		} );
 	}
 
-	/**
-	 * Clears all queued actions (e.g. in case of an error).
-	 *
-	 * @protected
-	 */
-	_clear() {
-		this._queuedActions = [];
-	}
-
 	/**
 	 * It handles queued actions one by one.
 	 *

+ 69 - 6
packages/ckeditor5-watchdog/tests/contextwatchdog.js

@@ -233,8 +233,6 @@ describe( 'ContextWatchdog', () => {
 				err = _err;
 			}
 
-			watchdog._actionQueue._clear();
-
 			await watchdog.destroy();
 
 			expect( err ).to.be.instanceOf( Error );
@@ -254,8 +252,6 @@ describe( 'ContextWatchdog', () => {
 				err = _err;
 			}
 
-			watchdog._actionQueue._clear();
-
 			await watchdog.destroy();
 
 			expect( err ).to.be.instanceOf( Error );
@@ -318,8 +314,6 @@ describe( 'ContextWatchdog', () => {
 				err = _err;
 			}
 
-			watchdog._actionQueue._clear();
-
 			await watchdog.destroy();
 
 			expect( err ).to.be.instanceOf( Error );
@@ -535,6 +529,75 @@ describe( 'ContextWatchdog', () => {
 
 				await watchdog.destroy();
 			} );
+
+			it( 'should handle removing and restarting at the same time', async () => {
+				watchdog = ContextWatchdog.for( Context, {} );
+
+				watchdog.add( {
+					editor1: {
+						type: 'editor',
+						creator: ( el, config ) => ClassicTestEditor.create( el, config ),
+						sourceElementOrData: element1,
+						config: {}
+					},
+					editor2: {
+						type: 'editor',
+						creator: ( el, config ) => ClassicTestEditor.create( el, config ),
+						sourceElementOrData: element2,
+						config: {}
+					}
+				} );
+
+				await watchdog.waitForReady();
+
+				const editor1 = watchdog.get( 'editor1' );
+
+				watchdog.remove( [ 'editor1' ] );
+
+				setTimeout( () => throwCKEditorError( 'foo', editor1 ) );
+
+				await waitCycle();
+				await watchdog.waitForReady();
+
+				expect( [ ...watchdog._watchdogs.keys() ] ).to.include( 'editor2' );
+				expect( [ ...watchdog._watchdogs.keys() ] ).to.not.include( 'editor1' );
+
+				await watchdog.destroy();
+			} );
+
+			it( 'should handle restarting the item instance many times', async () => {
+				watchdog = ContextWatchdog.for( Context, {} );
+
+				watchdog.add( {
+					editor1: {
+						type: 'editor',
+						creator: ( el, config ) => ClassicTestEditor.create( el, config ),
+						sourceElementOrData: element1,
+						config: {}
+					},
+					editor2: {
+						type: 'editor',
+						creator: ( el, config ) => ClassicTestEditor.create( el, config ),
+						sourceElementOrData: element2,
+						config: {}
+					}
+				} );
+
+				await watchdog.waitForReady();
+
+				const editorWatchdog = watchdog._watchdogs.get( 'editor1' );
+
+				setTimeout( () => throwCKEditorError( 'foo', editorWatchdog.editor ) );
+				setTimeout( () => throwCKEditorError( 'foo', editorWatchdog.editor ) );
+				setTimeout( () => throwCKEditorError( 'foo', editorWatchdog.editor ) );
+				setTimeout( () => throwCKEditorError( 'foo', editorWatchdog.editor ) );
+				await waitCycle();
+
+				expect( editorWatchdog.state ).to.equal( 'crashedPermanently' );
+				expect( watchdog.state ).to.equal( 'ready' );
+
+				await watchdog.destroy();
+			} );
 		} );
 	} );
 } );