+17
-6
carstore/nonarchive.go
+17
-6
carstore/nonarchive.go
···
74
74
75
75
func (cs *NonArchivalCarstore) loadCommitRefInfo(ctx context.Context, user models.Uid) (*commitRefInfo, error) {
76
76
var out commitRefInfo
77
-
if err := cs.db.Find(&out, "uid = ?", user).Error; err != nil {
78
-
return nil, err
77
+
wat := cs.db.Find(&out, "uid = ?", user)
78
+
if wat.Error != nil {
79
+
return nil, wat.Error
80
+
}
81
+
if wat.RowsAffected == 0 {
82
+
return nil, nil
79
83
}
80
-
81
84
return &out, nil
82
85
}
83
86
···
94
97
if err != nil {
95
98
return nil, err
96
99
}
100
+
if lastShard == nil {
101
+
return nil, nil
102
+
}
97
103
98
104
cs.putLastShardCache(lastShard)
99
105
return lastShard, nil
···
118
124
return nil
119
125
}
120
126
127
+
var commitRefZero = commitRefInfo{}
128
+
121
129
func (cs *NonArchivalCarstore) NewDeltaSession(ctx context.Context, user models.Uid, since *string) (*DeltaSession, error) {
122
130
ctx, span := otel.Tracer("carstore").Start(ctx, "NewSession")
123
131
defer span.End()
···
129
137
return nil, err
130
138
}
131
139
132
-
if since != nil && *since != lastShard.Rev {
140
+
if lastShard == nil {
141
+
// ok, no previous user state to refer to
142
+
lastShard = &commitRefZero
143
+
} else if since != nil && *since != lastShard.Rev {
133
144
cs.log.Warn("revision mismatch", "commitSince", since, "lastRev", lastShard.Rev, "err", ErrRepoBaseMismatch)
134
145
}
135
146
···
211
222
if err != nil {
212
223
return cid.Undef, err
213
224
}
214
-
if lastShard.ID == 0 {
225
+
if lastShard == nil || lastShard.ID == 0 {
215
226
return cid.Undef, nil
216
227
}
217
228
···
223
234
if err != nil {
224
235
return "", err
225
236
}
226
-
if lastShard.ID == 0 {
237
+
if lastShard == nil || lastShard.ID == 0 {
227
238
return "", nil
228
239
}
229
240
+22
-29
testing/integ_test.go
+22
-29
testing/integ_test.go
···
3
3
import (
4
4
"bytes"
5
5
"context"
6
-
"encoding/json"
7
-
"fmt"
8
6
"math/rand"
9
7
"strings"
10
8
"testing"
···
52
50
defer evts.Cancel()
53
51
54
52
bob := p1.MustNewUser(t, "bob.tpds")
55
-
fmt.Println("event 1")
53
+
t.Log("event 1")
56
54
e1 := evts.Next()
57
55
assert.NotNil(e1.RepoCommit)
58
56
assert.Equal(e1.RepoCommit.Repo, bob.DID())
59
57
60
58
alice := p1.MustNewUser(t, "alice.tpds")
61
-
fmt.Println("event 2")
59
+
t.Log("event 2")
62
60
e2 := evts.Next()
63
61
assert.NotNil(e2.RepoCommit)
64
62
assert.Equal(e2.RepoCommit.Repo, alice.DID())
···
69
67
_ = bp1
70
68
_ = ap1
71
69
72
-
fmt.Println("bob:", bob.DID())
73
-
fmt.Println("event 3")
70
+
t.Log("bob:", bob.DID())
71
+
t.Log("event 3")
74
72
e3 := evts.Next()
75
73
assert.Equal(e3.RepoCommit.Repo, bob.DID())
76
74
//assert.Equal(e3.RepoCommit.Ops[0].Kind, "createRecord")
77
75
78
-
fmt.Println("alice:", alice.DID())
79
-
fmt.Println("event 4")
76
+
t.Log("alice:", alice.DID())
77
+
t.Log("event 4")
80
78
e4 := evts.Next()
81
79
assert.Equal(e4.RepoCommit.Repo, alice.DID())
82
80
//assert.Equal(e4.RepoCommit.Ops[0].Kind, "createRecord")
···
85
83
pbevts := b1.Events(t, 2)
86
84
defer pbevts.Cancel()
87
85
88
-
fmt.Println("event 5")
86
+
t.Log("event 5")
89
87
pbe1 := pbevts.Next()
90
88
assert.Equal(*e3, *pbe1)
91
89
}
···
294
292
time.Sleep(time.Millisecond * 100)
295
293
296
294
initevt := evts.Next()
297
-
fmt.Println(initevt.RepoCommit)
295
+
t.Log(initevt.RepoCommit)
298
296
hcevt := evts.Next()
299
-
fmt.Println(hcevt.RepoHandle)
297
+
t.Log(hcevt.RepoHandle)
300
298
idevt := evts.Next()
301
-
fmt.Println(idevt.RepoIdentity)
299
+
t.Log(idevt.RepoIdentity)
302
300
}
303
301
304
302
func TestAccountEvent(t *testing.T) {
···
336
334
time.Sleep(time.Millisecond * 100)
337
335
338
336
initevt := evts.Next()
339
-
fmt.Println(initevt.RepoCommit)
337
+
t.Log(initevt.RepoCommit)
340
338
341
339
// Takedown
342
340
acevt := evts.Next()
343
-
fmt.Println(acevt.RepoAccount)
341
+
t.Log(acevt.RepoAccount)
344
342
assert.Equal(acevt.RepoAccount.Did, u.DID())
345
343
assert.Equal(acevt.RepoAccount.Active, false)
346
344
assert.Equal(*acevt.RepoAccount.Status, events.AccountStatusTakendown)
347
345
348
346
// Reactivate
349
347
acevt = evts.Next()
350
-
fmt.Println(acevt.RepoAccount)
348
+
t.Log(acevt.RepoAccount)
351
349
assert.Equal(acevt.RepoAccount.Did, u.DID())
352
350
assert.Equal(acevt.RepoAccount.Active, true)
353
351
assert.Equal(*acevt.RepoAccount.Status, events.AccountStatusActive)
354
352
355
353
// Deactivate
356
354
acevt = evts.Next()
357
-
fmt.Println(acevt.RepoAccount)
355
+
t.Log(acevt.RepoAccount)
358
356
assert.Equal(acevt.RepoAccount.Did, u.DID())
359
357
assert.Equal(acevt.RepoAccount.Active, false)
360
358
assert.Equal(*acevt.RepoAccount.Status, events.AccountStatusDeactivated)
361
359
362
360
// Reactivate
363
361
acevt = evts.Next()
364
-
fmt.Println(acevt.RepoAccount)
362
+
t.Log(acevt.RepoAccount)
365
363
assert.Equal(acevt.RepoAccount.Did, u.DID())
366
364
assert.Equal(acevt.RepoAccount.Active, true)
367
365
assert.Equal(*acevt.RepoAccount.Status, events.AccountStatusActive)
368
366
369
367
// Suspend
370
368
acevt = evts.Next()
371
-
fmt.Println(acevt.RepoAccount)
369
+
t.Log(acevt.RepoAccount)
372
370
assert.Equal(acevt.RepoAccount.Did, u.DID())
373
371
assert.Equal(acevt.RepoAccount.Active, false)
374
372
assert.Equal(*acevt.RepoAccount.Status, events.AccountStatusSuspended)
375
373
376
374
// Reactivate
377
375
acevt = evts.Next()
378
-
fmt.Println(acevt.RepoAccount)
376
+
t.Log(acevt.RepoAccount)
379
377
assert.Equal(acevt.RepoAccount.Did, u.DID())
380
378
assert.Equal(acevt.RepoAccount.Active, true)
381
379
assert.Equal(*acevt.RepoAccount.Status, events.AccountStatusActive)
···
387
385
time.Sleep(time.Millisecond * 20)
388
386
389
387
acevt = evts.Next()
390
-
fmt.Println(acevt.RepoAccount)
388
+
t.Log(acevt.RepoAccount)
391
389
assert.Equal(acevt.RepoAccount.Did, u.DID())
392
390
assert.Equal(acevt.RepoAccount.Active, false)
393
391
assert.Equal(*acevt.RepoAccount.Status, events.AccountStatusTakendown)
···
399
397
time.Sleep(time.Millisecond * 20)
400
398
401
399
acevt = evts.Next()
402
-
fmt.Println(acevt.RepoAccount)
400
+
t.Log(acevt.RepoAccount)
403
401
assert.Equal(acevt.RepoAccount.Did, u.DID())
404
402
assert.Equal(acevt.RepoAccount.Active, true)
405
403
assert.Equal(*acevt.RepoAccount.Status, events.AccountStatusActive)
···
467
465
468
466
last := es2.Next()
469
467
assert.Equal(alice.did, last.RepoCommit.Repo)
470
-
}
471
-
472
-
func jsonPrint(v any) {
473
-
b, _ := json.Marshal(v)
474
-
fmt.Println(string(b))
475
468
}
476
469
477
470
func commitFromSlice(t *testing.T, slice []byte, rcid cid.Cid) *repo.SignedCommit {
···
560
553
defer evts.Cancel()
561
554
562
555
bob := p1.MustNewUser(t, "bob.tpds")
563
-
fmt.Println("event 1")
556
+
t.Log("event 1")
564
557
e1 := evts.Next()
565
558
assert.NotNil(e1.RepoCommit)
566
559
assert.Equal(e1.RepoCommit.Repo, bob.DID())
567
-
fmt.Println(e1.RepoCommit.Ops[0])
560
+
t.Log(e1.RepoCommit.Ops[0])
568
561
569
562
ctx := context.TODO()
570
563
rm := p1.server.Repoman()
···
573
566
}
574
567
575
568
e2 := evts.Next()
576
-
//fmt.Println(e2.RepoCommit.Ops[0])
569
+
//t.Log(e2.RepoCommit.Ops[0])
577
570
assert.Equal(len(e2.RepoCommit.Ops), 0)
578
571
assert.Equal(e2.RepoCommit.Repo, bob.DID())
579
572
}