@@ -710,22 +710,66 @@ func TestBlocking(t *testing.T) {
710710 t .Run ("MarshalJSON" , func (t * testing.T ) {
711711 t .Parallel ()
712712
713- elems := []int {3 , 2 , 1 }
713+ t .Run ("HasElements" , func (t * testing.T ) {
714+ t .Parallel ()
714715
715- q := queue . NewBlocking ( elems )
716+ elems := [] int { 3 , 2 , 1 }
716717
717- marshaled , err := json .Marshal (q )
718- if err != nil {
719- t .Fatalf ("expected no error, got %v" , err )
720- }
718+ q := queue .NewBlocking (elems )
721719
722- expectedMarshaled := []byte (`[3,2,1]` )
723- if ! bytes .Equal (expectedMarshaled , marshaled ) {
724- t .Fatalf ("expected marshaled to be %s, got %s" , expectedMarshaled , marshaled )
725- }
720+ marshaled , err := json .Marshal (q )
721+ if err != nil {
722+ t .Fatalf ("expected no error, got %v" , err )
723+ }
724+
725+ expectedMarshaled := []byte (`[3,2,1]` )
726+ if ! bytes .Equal (expectedMarshaled , marshaled ) {
727+ t .Fatalf ("expected marshaled to be %s, got %s" , expectedMarshaled , marshaled )
728+ }
729+ })
730+
731+ t .Run ("FailMarshal" , func (t * testing.T ) {
732+ t .Parallel ()
733+
734+ q := queue .NewBlocking ([]failMarshal {{}})
735+
736+ marshaled , err := json .Marshal (q )
737+ if err == nil {
738+ t .Fatalf ("expected error, got nil" )
739+ }
740+
741+ if marshaled != nil {
742+ t .Fatalf ("expected marshaled to be nil, got %s" , marshaled )
743+ }
744+ })
745+
746+ t .Run ("Empty" , func (t * testing.T ) {
747+ t .Parallel ()
748+
749+ q := queue.NewBlocking [int ](nil )
750+
751+ marshaled , err := json .Marshal (q )
752+ if err != nil {
753+ t .Fatalf ("expected no error, got %v" , err )
754+ }
755+
756+ expectedMarshaled := []byte (`[]` )
757+ if ! bytes .Equal (expectedMarshaled , marshaled ) {
758+ t .Fatalf ("expected marshaled to be %s, got %s" , expectedMarshaled , marshaled )
759+ }
760+ })
726761 })
727762}
728763
764+ // failMarshal is a helper to fail the json marshalling of the queues
765+ type failMarshal struct {}
766+
767+ var errFailMarshal = errors .New ("intentional marshal error" )
768+
769+ func (f failMarshal ) MarshalJSON () ([]byte , error ) {
770+ return nil , errFailMarshal
771+ }
772+
729773func testResetOnMultipleRoutinesFunc [T comparable ](
730774 ids []T ,
731775 totalRoutines int ,
0 commit comments