io.monitors.recursive: Bug - <recursive-monitor> could fail and leak a file monitor.
Fix - Monitors tests were "leaking" dummy-monitors objects.db4
							parent
							
								
									662e215c7e
								
							
						
					
					
						commit
						36a4eb7ee1
					
				|  | @ -1,19 +1,19 @@ | ||||||
| USING: accessors math kernel namespaces continuations | USING: accessors math kernel namespaces continuations | ||||||
| io.files io.monitors io.monitors.recursive io.backend | io.files io.monitors io.monitors.recursive io.backend | ||||||
| concurrency.mailboxes tools.test destructors io.files.info | concurrency.mailboxes tools.test destructors io.files.info | ||||||
| io.pathnames io.files.temp io.directories.hierarchy ; | io.pathnames io.files.temp io.directories.hierarchy fry ; | ||||||
| IN: io.monitors.recursive.tests | IN: io.monitors.recursive.tests | ||||||
| 
 | 
 | ||||||
| SINGLETON: mock-io-backend | SINGLETON: mock-io-backend | ||||||
| 
 | 
 | ||||||
| TUPLE: counter i ; | TUPLE: mock-counter i ; | ||||||
| 
 | 
 | ||||||
| SYMBOL: dummy-monitor-created | SYMBOL: dummy-monitor-created | ||||||
| SYMBOL: dummy-monitor-disposed | SYMBOL: dummy-monitor-disposed | ||||||
| 
 | 
 | ||||||
| TUPLE: dummy-monitor < monitor ; | TUPLE: dummy-monitor < monitor ; | ||||||
| 
 | 
 | ||||||
| M: dummy-monitor dispose | M: dummy-monitor dispose* | ||||||
|     drop dummy-monitor-disposed get [ 1 + ] change-i drop ; |     drop dummy-monitor-disposed get [ 1 + ] change-i drop ; | ||||||
| 
 | 
 | ||||||
| M: mock-io-backend (monitor) | M: mock-io-backend (monitor) | ||||||
|  | @ -28,8 +28,8 @@ M: mock-io-backend (monitor) | ||||||
| M: mock-io-backend link-info | M: mock-io-backend link-info | ||||||
|     global [ link-info ] with-variables ; |     global [ link-info ] with-variables ; | ||||||
| 
 | 
 | ||||||
| [ ] [ 0 counter boa dummy-monitor-created set ] unit-test | [ ] [ 0 mock-counter boa dummy-monitor-created set ] unit-test | ||||||
| [ ] [ 0 counter boa dummy-monitor-disposed set ] unit-test | [ ] [ 0 mock-counter boa dummy-monitor-disposed set ] unit-test | ||||||
| 
 | 
 | ||||||
| [ ] [ | [ ] [ | ||||||
|     mock-io-backend io-backend [ |     mock-io-backend io-backend [ | ||||||
|  | @ -44,14 +44,18 @@ M: mock-io-backend link-info | ||||||
| [ "doesnotexist" temp-file delete-tree ] ignore-errors | [ "doesnotexist" temp-file delete-tree ] ignore-errors | ||||||
| 
 | 
 | ||||||
| [ | [ | ||||||
|  |     0 mock-counter boa dummy-monitor-created [ | ||||||
|         mock-io-backend io-backend [ |         mock-io-backend io-backend [ | ||||||
|             "doesnotexist" temp-file <mailbox> <recursive-monitor> dispose |             "doesnotexist" temp-file <mailbox> <recursive-monitor> dispose | ||||||
|         ] with-variable |         ] with-variable | ||||||
|  |     ] with-variable | ||||||
| ] must-fail | ] must-fail | ||||||
| 
 | 
 | ||||||
|  | [ ] [ 0 mock-counter boa dummy-monitor-created set ] unit-test | ||||||
|  | [ ] [ 0 mock-counter boa dummy-monitor-disposed set ] unit-test | ||||||
|  | 
 | ||||||
|  | ! Test that disposing twice is allowed | ||||||
| [ ] [ | [ ] [ | ||||||
|     mock-io-backend io-backend [ |  | ||||||
|     "" resource-path <mailbox> <recursive-monitor> |     "" resource-path <mailbox> <recursive-monitor> | ||||||
|     [ dispose ] [ dispose ] bi |     [ dispose ] [ dispose ] bi | ||||||
|     ] with-variable |  | ||||||
| ] unit-test | ] unit-test | ||||||
|  |  | ||||||
|  | @ -100,9 +100,11 @@ M: recursive-monitor dispose* | ||||||
|     ready>> ?promise ?linked drop ; |     ready>> ?promise ?linked drop ; | ||||||
| 
 | 
 | ||||||
| : <recursive-monitor> ( path mailbox -- monitor ) | : <recursive-monitor> ( path mailbox -- monitor ) | ||||||
|  |     '[ _ _ | ||||||
|         [ absolute-path ] dip |         [ absolute-path ] dip | ||||||
|     recursive-monitor new-monitor |         recursive-monitor new-monitor |dispose | ||||||
|             H{ } clone >>children |             H{ } clone >>children | ||||||
|             <promise> >>ready |             <promise> >>ready | ||||||
|         dup start-pump-thread |         dup start-pump-thread | ||||||
|     dup wait-for-ready ; |         dup wait-for-ready | ||||||
|  |     ] with-destructors ; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue