@@ -481,6 +481,45 @@ test('can mount a drive within a remote hyperdrive multiple times', async t => {
481
481
t . end ( )
482
482
} )
483
483
484
+ test ( 'can mount a versioned drive within a remote hyperdrive' , async t => {
485
+ const { client, cleanup } = await createOne ( )
486
+
487
+ try {
488
+ const drive1 = await client . drive . get ( )
489
+
490
+ const drive2 = await client . drive . get ( )
491
+ await drive2 . writeFile ( 'hamster' , 'wheel' )
492
+ const version1 = await drive2 . version ( )
493
+ await drive2 . writeFile ( 'blah' , 'blahblah' )
494
+
495
+ await drive1 . mount ( 'a' , { key : drive2 . key } )
496
+ await drive1 . mount ( 'aStatic' , { key : drive2 . key , version : version1 } )
497
+
498
+ await drive1 . writeFile ( 'a/hello' , 'world' )
499
+ await drive1 . writeFile ( 'adios' , 'amigo' )
500
+
501
+ t . same ( await drive1 . readFile ( 'adios' ) , Buffer . from ( 'amigo' ) )
502
+ t . same ( await drive1 . readFile ( 'a/hello' ) , Buffer . from ( 'world' ) )
503
+ t . same ( await drive2 . readFile ( 'hello' ) , Buffer . from ( 'world' ) )
504
+ t . same ( await drive2 . readFile ( 'hamster' ) , Buffer . from ( 'wheel' ) )
505
+ t . same ( await drive1 . readFile ( 'aStatic/hamster' ) , Buffer . from ( 'wheel' ) )
506
+ try {
507
+ await drive1 . readFile ( 'aStatic/blah' )
508
+ t . fail ( 'aStatic should be a versioned mount' )
509
+ } catch ( err ) {
510
+ t . true ( err )
511
+ }
512
+
513
+ await drive1 . close ( )
514
+ await drive2 . close ( )
515
+ } catch ( err ) {
516
+ t . fail ( err )
517
+ }
518
+
519
+ await cleanup ( )
520
+ t . end ( )
521
+ } )
522
+
484
523
test ( 'can unmount a drive within a remote hyperdrive' , async t => {
485
524
const { client, cleanup } = await createOne ( )
486
525
@@ -604,8 +643,7 @@ test('can create a symlink to directories', async t => {
604
643
t . end ( )
605
644
} )
606
645
607
- // TODO: Stop skipping once we've updated hyperdrive/mountable-hypertrie to nanoresource.
608
- test . skip ( 'drives are closed when all corresponding sessions are closed' , async t => {
646
+ test ( 'drives are closed when all corresponding sessions are closed' , async t => {
609
647
const { client, cleanup, daemon } = await createOne ( )
610
648
611
649
try {
@@ -630,6 +668,66 @@ test.skip('drives are closed when all corresponding sessions are closed', async
630
668
t . end ( )
631
669
} )
632
670
671
+ test ( 'reopening a drive after previously closed works' , async t => {
672
+ const { client, cleanup, daemon } = await createOne ( )
673
+
674
+ try {
675
+ var drive = await client . drive . get ( )
676
+ const driveKey = drive . key
677
+ await drive . writeFile ( 'a' , 'a' )
678
+ await drive . writeFile ( 'b' , 'b' )
679
+ await drive . writeFile ( 'c' , 'c' )
680
+ const otherDrive = await client . drive . get ( { key : driveKey } )
681
+ const checkout1 = await client . drive . get ( { key : driveKey , version : 1 } )
682
+
683
+ await drive . close ( )
684
+ t . same ( daemon . drives . _drives . size , 2 )
685
+ await otherDrive . close ( )
686
+ t . same ( daemon . drives . _drives . size , 2 )
687
+ await checkout1 . close ( )
688
+ t . same ( daemon . drives . _drives . size , 0 )
689
+
690
+ drive = await client . drive . get ( { key : driveKey } )
691
+ await drive . writeFile ( 'd' , 'd' )
692
+ const contents = await drive . readFile ( 'a' )
693
+ t . same ( contents , Buffer . from ( 'a' ) )
694
+ } catch ( err ) {
695
+ t . fail ( err )
696
+ }
697
+
698
+ await cleanup ( )
699
+ t . end ( )
700
+ } )
701
+
702
+ test ( 'many quick closes/reopens' , async t => {
703
+ const NUM_CYCLES = 10
704
+ const { client, cleanup, daemon } = await createOne ( )
705
+ var driveKey = null
706
+ const expected = new Array ( NUM_CYCLES ) . fill ( 0 ) . map ( ( _ , i ) => '' + i )
707
+
708
+ try {
709
+ for ( let i = 0 ; i < NUM_CYCLES ; i ++ ) {
710
+ var drive = await client . drive . get ( { key : driveKey } )
711
+ if ( ! driveKey ) driveKey = drive . key
712
+ await drive . writeFile ( expected [ i ] , expected [ i ] )
713
+ await drive . close ( )
714
+ if ( daemon . drives . _drives . size !== 0 ) t . fail ( 'session close did not trigger drive close' )
715
+ }
716
+ drive = await client . drive . get ( { key : driveKey } )
717
+ const actual = [ ]
718
+ for ( let i = 0 ; i < NUM_CYCLES ; i ++ ) {
719
+ const contents = await drive . readFile ( expected [ i ] )
720
+ actual [ i ] = contents . toString ( 'utf8' )
721
+ }
722
+ t . same ( expected , actual )
723
+ } catch ( err ) {
724
+ t . fail ( err )
725
+ }
726
+
727
+ await cleanup ( )
728
+ t . end ( )
729
+ } )
730
+
633
731
test ( 'drives are writable after a daemon restart' , async t => {
634
732
var { dir, client, cleanup } = await createOne ( )
635
733
@@ -656,6 +754,33 @@ test('drives are writable after a daemon restart', async t => {
656
754
t . end ( )
657
755
} )
658
756
757
+ test ( 'cores are not closed incorrectly during the initial rejoin' , async t => {
758
+ var { dir, client, cleanup } = await createOne ( )
759
+
760
+ try {
761
+ var drive = await client . drive . get ( )
762
+ const driveKey = drive . key
763
+ await drive . writeFile ( 'a' , 'a' )
764
+ await drive . configureNetwork ( { announce : true , lookup : true , remember : true } )
765
+
766
+ await cleanup ( { persist : true } )
767
+
768
+ const newDaemon = await createOne ( { dir } )
769
+ client = newDaemon . client
770
+ cleanup = newDaemon . cleanup
771
+ drive = await client . drive . get ( { key : driveKey } )
772
+
773
+ t . same ( await drive . readFile ( 'a' ) , Buffer . from ( 'a' ) )
774
+ await drive . writeFile ( 'b' , 'b' )
775
+ t . same ( await drive . readFile ( 'b' ) , Buffer . from ( 'b' ) )
776
+ } catch ( err ) {
777
+ t . fail ( err )
778
+ }
779
+
780
+ await cleanup ( )
781
+ t . end ( )
782
+ } )
783
+
659
784
test ( 'mounts are writable in memory-only mode' , async t => {
660
785
var { client, cleanup } = await createOne ( { memoryOnly : true } )
661
786
0 commit comments