@@ -721,6 +721,81 @@ func BenchmarkSQLSerial(b *testing.B) {
721721 }
722722}
723723
724+ func TestFutureMultipleGetGetTyped (t * testing.T ) {
725+ conn := test_helpers .ConnectWithValidation (t , server , opts )
726+ defer conn .Close ()
727+
728+ fut := conn .Call17Async ("simple_concat" , []interface {}{"1" })
729+
730+ for i := 0 ; i < 30 ; i ++ {
731+ // [0, 10) fut.Get()
732+ // [10, 20) fut.GetTyped()
733+ // [20, 30) Mix
734+ get := false
735+ if (i < 10 ) || (i >= 20 && i % 2 == 0 ) {
736+ get = true
737+ }
738+
739+ if get {
740+ resp , err := fut .Get ()
741+ if err != nil {
742+ t .Errorf ("Failed to call Get(): %s" , err )
743+ }
744+ if val , ok := resp .Data [0 ].(string ); ! ok || val != "11" {
745+ t .Errorf ("Wrong Get() result: %v" , resp .Data )
746+ }
747+ } else {
748+ tpl := struct {
749+ Val string
750+ }{}
751+ err := fut .GetTyped (& tpl )
752+ if err != nil {
753+ t .Errorf ("Failed to call GetTyped(): %s" , err )
754+ }
755+ if tpl .Val != "11" {
756+ t .Errorf ("Wrong GetTyped() result: %v" , tpl )
757+ }
758+ }
759+ }
760+ }
761+
762+ func TestFutureMultipleGetWithError (t * testing.T ) {
763+ conn := test_helpers .ConnectWithValidation (t , server , opts )
764+ defer conn .Close ()
765+
766+ fut := conn .Call17Async ("non_exist" , []interface {}{"1" })
767+
768+ for i := 0 ; i < 2 ; i ++ {
769+ if _ , err := fut .Get (); err == nil {
770+ t .Fatalf ("An error expected" )
771+ }
772+ }
773+ }
774+
775+ func TestFutureMultipleGetTypedWithError (t * testing.T ) {
776+ conn := test_helpers .ConnectWithValidation (t , server , opts )
777+ defer conn .Close ()
778+
779+ fut := conn .Call17Async ("simple_concat" , []interface {}{"1" })
780+
781+ wrongTpl := struct {
782+ Val int
783+ }{}
784+ goodTpl := struct {
785+ Val string
786+ }{}
787+
788+ if err := fut .GetTyped (& wrongTpl ); err == nil {
789+ t .Fatalf ("An error expected" )
790+ }
791+ if err := fut .GetTyped (& goodTpl ); err != nil {
792+ t .Fatalf ("Unexpected error: %s" , err )
793+ }
794+ if goodTpl .Val != "11" {
795+ t .Fatalf ("Wrong result: %s" , goodTpl .Val )
796+ }
797+ }
798+
724799///////////////////
725800
726801func TestClient (t * testing.T ) {
@@ -1069,7 +1144,7 @@ func TestClientSessionPush(t *testing.T) {
10691144 } else if len (resp .Data ) < 1 {
10701145 t .Errorf ("Response.Data is empty after Call17Async" )
10711146 } else if val , err := convertUint64 (resp .Data [0 ]); err != nil || val != pushMax {
1072- t .Errorf ("result is not {{1}} : %v" , resp .Data )
1147+ t .Errorf ("Result is not %d : %v" , pushMax , resp .Data )
10731148 }
10741149
10751150 // It will will be iterated with a timeout.
@@ -1103,7 +1178,7 @@ func TestClientSessionPush(t *testing.T) {
11031178 } else {
11041179 respCnt += 1
11051180 if val , err := convertUint64 (resp .Data [0 ]); err != nil || val != pushMax {
1106- t .Errorf ("result is not {{1}} : %v" , resp .Data )
1181+ t .Errorf ("Result is not %d : %v" , pushMax , resp .Data )
11071182 }
11081183 }
11091184 }
@@ -1120,6 +1195,26 @@ func TestClientSessionPush(t *testing.T) {
11201195 t .Errorf ("Expect %d responses but got %d" , 1 , respCnt )
11211196 }
11221197 }
1198+
1199+ // We can collect original responses after iterations.
1200+ for _ , fut := range []* Future {fut0 , fut1 , fut2 } {
1201+ resp , err := fut .Get ()
1202+ if err != nil {
1203+ t .Errorf ("Unable to call fut.Get(): %s" , err )
1204+ } else if val , err := convertUint64 (resp .Data [0 ]); err != nil || val != pushMax {
1205+ t .Errorf ("Result is not %d: %v" , pushMax , resp .Data )
1206+ }
1207+
1208+ tpl := struct {
1209+ Val int
1210+ }{}
1211+ err = fut .GetTyped (& tpl )
1212+ if err != nil {
1213+ t .Errorf ("Unable to call fut.GetTyped(): %s" , err )
1214+ } else if tpl .Val != pushMax {
1215+ t .Errorf ("Result is not %d: %d" , pushMax , tpl .Val )
1216+ }
1217+ }
11231218}
11241219
11251220const (
0 commit comments