Skip to content

Commit 1909e12

Browse files
committed
test: saving big data
1 parent 812d5aa commit 1909e12

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

examples/example-react-native/src/tests/BasicTests.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,25 @@ const BasicTests: React.FC<Props> = ({ storage }) => {
9090
}
9191
};
9292

93+
const saveBigData = async () => {
94+
try {
95+
const key = "big-data";
96+
const data = JSON.stringify(
97+
new Array(500_000).fill("a")
98+
);
99+
addLog(`Saving ${key} with data size ${data.length}`);
100+
const timeNow = +Date.now();
101+
await storage.setItem(key, data);
102+
addLog(`saving took ${+Date.now() - timeNow}ms`);
103+
104+
addLog(`reading ${key}`);
105+
const res = await storage.getItem(key);
106+
addLog(`size of result: ${res?.length}`);
107+
} catch (e) {
108+
reportError(e);
109+
}
110+
};
111+
93112
return (
94113
<View style={{ paddingHorizontal: 16, flex: 1 }}>
95114
<View style={{ gap: 8 }}>
@@ -98,6 +117,7 @@ const BasicTests: React.FC<Props> = ({ storage }) => {
98117
onPress={testSingleSetCrudKey}
99118
/>
100119
<Button title="Test CRUD on many entries" onPress={testMultiKey} />
120+
<Button title="Test big data" onPress={saveBigData} />
101121
</View>
102122

103123
<View style={{ width: "100%", alignItems: "flex-end" }}>

examples/example-web/src/tests/BasicTests.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,23 @@ const BasicTests: React.FC<Props> = ({ storage }) => {
8989
}
9090
};
9191

92+
const saveBigData = async () => {
93+
try {
94+
const key = "big-data";
95+
const data = JSON.stringify(new Array(500_000).fill("a"));
96+
addLog(`Saving ${key} with data size ${data.length}`);
97+
const timeNow = +Date.now();
98+
await storage.setItem(key, data);
99+
addLog(`saving took ${+Date.now() - timeNow}ms`);
100+
101+
addLog(`reading ${key}`);
102+
const res = await storage.getItem(key);
103+
addLog(`size of result: ${res?.length}`);
104+
} catch (e) {
105+
reportError(e);
106+
}
107+
};
108+
92109
return (
93110
<div className="flex flex-col items-center px-4">
94111
<div className="flex flex-col max-w-64 items-center gap-2">
@@ -105,6 +122,13 @@ const BasicTests: React.FC<Props> = ({ storage }) => {
105122
>
106123
Test CRUD on many entries
107124
</button>
125+
126+
<button
127+
onClick={saveBigData}
128+
className="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700"
129+
>
130+
Test big data
131+
</button>
108132
</div>
109133

110134
<div className="w-full flex justify-end max-w-1/4 mt-2">

0 commit comments

Comments
 (0)