@@ -7,6 +7,7 @@ extern crate openssl;
7
7
#[ cfg( feature = "openssl" ) ]
8
8
use openssl:: ssl:: { SslContext , SslMethod } ;
9
9
use std:: thread;
10
+ use std:: io;
10
11
11
12
use postgres:: { HandleNotice ,
12
13
Notification ,
@@ -605,48 +606,6 @@ fn test_notifications_next_block() {
605
606
} , or_panic ! ( notifications. next_block( ) ) ) ;
606
607
}
607
608
608
- /*
609
- #[test]
610
- fn test_notifications_next_block_for() {
611
- let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
612
- or_panic!(conn.execute("LISTEN test_notifications_next_block_for", &[]));
613
-
614
- let _t = thread::spawn(|| {
615
- let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
616
- timer::sleep(Duration::milliseconds(500));
617
- or_panic!(conn.execute("NOTIFY test_notifications_next_block_for, 'foo'", &[]));
618
- });
619
-
620
- let mut notifications = conn.notifications();
621
- check_notification(Notification {
622
- pid: 0,
623
- channel: "test_notifications_next_block_for".to_string(),
624
- payload: "foo".to_string()
625
- }, or_panic!(notifications.next_block_for(Duration::seconds(2)).unwrap()));
626
- }
627
-
628
- #[test]
629
- fn test_notifications_next_block_for_timeout() {
630
- let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
631
- or_panic!(conn.execute("LISTEN test_notifications_next_block_for_timeout", &[]));
632
-
633
- let _t = thread::spawn(|| {
634
- let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
635
- timer::sleep(Duration::seconds(2));
636
- or_panic!(conn.execute("NOTIFY test_notifications_next_block_for_timeout, 'foo'", &[]));
637
- });
638
-
639
- let mut notifications = conn.notifications();
640
- match notifications.next_block_for(Duration::milliseconds(500)) {
641
- None => {}
642
- Some(Err(e)) => panic!("Unexpected error {:?}", e),
643
- Some(Ok(_)) => panic!("expected error"),
644
- }
645
-
646
- or_panic!(conn.execute("SELECT 1", &[]));
647
- }
648
- */
649
-
650
609
#[ test]
651
610
// This test is pretty sad, but I don't think there's a better way :(
652
611
fn test_cancel_query ( ) {
@@ -762,6 +721,28 @@ fn test_batch_execute_copy_from_err() {
762
721
}
763
722
}
764
723
724
+ #[ test]
725
+ fn test_copy_io_error ( ) {
726
+ struct ErrorReader ;
727
+
728
+ impl io:: Read for ErrorReader {
729
+ fn read ( & mut self , _: & mut [ u8 ] ) -> io:: Result < usize > {
730
+ Err ( io:: Error :: new ( io:: ErrorKind :: AddrNotAvailable , "boom" ) )
731
+ }
732
+ }
733
+
734
+ let conn = or_panic ! ( Connection :: connect( "postgres://postgres@localhost" , & SslMode :: None ) ) ;
735
+ or_panic ! ( conn. execute( "CREATE TEMPORARY TABLE foo (id INT)" , & [ ] ) ) ;
736
+ let stmt = or_panic ! ( conn. prepare( "COPY foo (id) FROM STDIN" ) ) ;
737
+ match stmt. copy_in ( & [ ] , & mut ErrorReader ) {
738
+ Err ( Error :: IoError ( ref e) ) if e. kind ( ) == io:: ErrorKind :: AddrNotAvailable => { }
739
+ Err ( err) => panic ! ( "Unexpected error {:?}" , err) ,
740
+ _ => panic ! ( "Expected error" ) ,
741
+ }
742
+
743
+ or_panic ! ( conn. execute( "SELECT 1" , & [ ] ) ) ;
744
+ }
745
+
765
746
#[ test]
766
747
fn test_copy ( ) {
767
748
let conn = or_panic ! ( Connection :: connect( "postgres://postgres@localhost" , & SslMode :: None ) ) ;
0 commit comments