Index: tests/ioCmd.test
===================================================================
--- tests/ioCmd.test
+++ tests/ioCmd.test
@@ -2584,36 +2584,52 @@
 } -result {{write rc* ABC} {watch rc* write} {}} \
     -constraints {testchannel thread}
 
 test iocmd.tf-24.16 {chan write, note the background flush setup by close due to the EAGAIN leaving data in buffers.} -match glob -setup {
     set res {}
+    set again 1
+    proc blah s {exec echo $s > /dev/tty}
     proc foo {args} {
+	blah FOO:$args
 	oninit; onfinal; track
 	# Note: The EAGAIN signals that the channel cannot accept
 	# write requests right now, this in turn causes the IO core to
 	# request the generation of writable events (see expected
 	# result below, and compare to case 24.14 above).
-	error EAGAIN
+	if {[lindex $args 0]=="write"} {
+	    if {$::again} {
+		set ::again 0
+		after 400 {blah POSTEVENT;chan postevent $::c w}
+		blah RET:EAGAIN
+		error EAGAIN
+	    } else {
+		set n  [string length [lindex $args 2]]
+		blah RET:$n
+		return $n
+	    }
+	}
     }
     set c [chan create {r w} foo]
     fconfigure $c -blocking 0
 } -body {
     notes [inthread $c {
 	note [puts -nonewline $c ABC ; flush $c]
 	close $c
+	after 200 {set ::finalflush 1}
+	vwait ::finalflush
 	notes
     } c]
     # Replace handler with all-tracking one which doesn't error.
     # This will tell us if a write-due-flush is there.
-    proc foo {args} { onfinal; note BG ; track ; set ::endbody-24.16 1}
+    proc foo {args} {blah FOO2:$args; onfinal; note BG ; track ; set ::endbody-24.16 1;if {[lindex args 0]=="write"} {return [string length [lindex $args 2]]}}
     # Flush (sic!) the event-queue to capture the write from a
     # BG-flush.
     after 1000 {set ::endbody-24.16 2}
     vwait endbody-24.16
     set res
 } -cleanup {
-    proc foo {args} {onfinal; set ::done-24.16 1; return 3}
+    proc foo {args} {blah FOO3:$args;onfinal; set ::done-24.16 1; if {[lindex args 0]=="write"} {return [string length [lindex $args 2]]}}
     after 1000 {set ::done-24.16 2}
     vwait done-24.16
     rename foo {}
     unset res
 } -result {{write rc* ABC} {watch rc* write} {} BG {write rc* ABC}} \

