@@ -110,6 +110,69 @@ func TestRead_CanEarlyExitIfNoNewVGtidInPeek(t *testing.T) {
110110 assert .Contains (t , dbl .messages [len (dbl .messages )- 1 ].message , "no new rows found, exiting" )
111111}
112112
113+ func TestRead_ReturnsLatestCursorSyncError (t * testing.T ) {
114+ dbl := & dbLogger {}
115+ ped := connectClient {}
116+ getKeyspaceTableColumnsFunc := func (ctx context.Context , keyspaceName string , tableName string ) ([]MysqlColumn , error ) {
117+ return []MysqlColumn {{Name : "id" , Type : "bigint" , IsPrimaryKey : true }, {Name : "email" , Type : "varchar(256)" , IsPrimaryKey : false }}, nil
118+ }
119+ mysqlClient := NewTestMysqlClient (getKeyspaceTableColumnsFunc )
120+ ped .Mysql = & mysqlClient
121+ tc := & psdbconnect.TableCursor {
122+ Shard : "-" ,
123+ Position : "THIS_IS_A_SHARD_GTID" ,
124+ Keyspace : "connect-test" ,
125+ }
126+
127+ cc := clientConnectionMock {
128+ syncFn : func (ctx context.Context , in * psdbconnect.SyncRequest , opts ... grpc.CallOption ) (psdbconnect.Connect_SyncClient , error ) {
129+ assert .Equal (t , "current" , in .Cursor .Position )
130+ return nil , errors .New ("sync unavailable" )
131+ },
132+ }
133+ ped .clientFn = func (ctx context.Context , ps PlanetScaleSource ) (psdbconnect.ConnectClient , error ) {
134+ return & cc , nil
135+ }
136+
137+ sc , err := ped .Read (context .Background (), dbl , PlanetScaleSource {}, "customers" , nil , tc , nil , nil , nil )
138+ assert .Nil (t , sc )
139+ assert .ErrorContains (t , err , "Unable to get latest cursor position" )
140+ assert .ErrorContains (t , err , "sync unavailable" )
141+ assert .Equal (t , 1 , cc .syncFnInvokedCount )
142+ }
143+
144+ func TestRead_ReturnsLatestCursorRecvError (t * testing.T ) {
145+ dbl := & dbLogger {}
146+ ped := connectClient {}
147+ getKeyspaceTableColumnsFunc := func (ctx context.Context , keyspaceName string , tableName string ) ([]MysqlColumn , error ) {
148+ return []MysqlColumn {{Name : "id" , Type : "bigint" , IsPrimaryKey : true }, {Name : "email" , Type : "varchar(256)" , IsPrimaryKey : false }}, nil
149+ }
150+ mysqlClient := NewTestMysqlClient (getKeyspaceTableColumnsFunc )
151+ ped .Mysql = & mysqlClient
152+ tc := & psdbconnect.TableCursor {
153+ Shard : "-" ,
154+ Position : "THIS_IS_A_SHARD_GTID" ,
155+ Keyspace : "connect-test" ,
156+ }
157+
158+ getCurrentVGtidClient := & connectSyncClientMock {}
159+ cc := clientConnectionMock {
160+ syncFn : func (ctx context.Context , in * psdbconnect.SyncRequest , opts ... grpc.CallOption ) (psdbconnect.Connect_SyncClient , error ) {
161+ assert .Equal (t , "current" , in .Cursor .Position )
162+ return getCurrentVGtidClient , nil
163+ },
164+ }
165+ ped .clientFn = func (ctx context.Context , ps PlanetScaleSource ) (psdbconnect.ConnectClient , error ) {
166+ return & cc , nil
167+ }
168+
169+ sc , err := ped .Read (context .Background (), dbl , PlanetScaleSource {}, "customers" , nil , tc , nil , nil , nil )
170+ assert .Nil (t , sc )
171+ assert .ErrorContains (t , err , "Unable to get latest cursor position" )
172+ assert .ErrorContains (t , err , "EOF" )
173+ assert .Equal (t , 1 , cc .syncFnInvokedCount )
174+ }
175+
113176func TestRead_CanPickPrimaryForShardedKeyspaces (t * testing.T ) {
114177 dbl := & dbLogger {}
115178 ped := connectClient {}
0 commit comments