This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AWS from 'aws-sdk' | |
import { uuid } from 'short-uuid' | |
import { yesno } from 'yesno-http' | |
yesno.spy() | |
const documentClient = new AWS.DynamoDB.DocumentClient({ | |
apiVersion: 'latest', | |
}) | |
const putItem = (Item: any, table: string) => | |
documentClient.put({ TableName: table, Item: Item }).promise() | |
const getItem = (Key: any, table: string) => | |
documentClient.get({ TableName: table, Key, ConsistentRead: true }).promise() | |
const transactPutItem = (Item: any, table: string) => | |
documentClient | |
.transactWrite({ TransactItems: [{ Put: { TableName: table, Item: Item } }] }) | |
.promise() | |
const deleteItem = (Key: any, table: string) => | |
documentClient.delete({ TableName: table, Key }).promise() | |
const runTest = async (i: number) => { | |
const tableName = 'onin-dev-Accounts-2' | |
const item = { accountID: uuid() } | |
console.log('putting', i) | |
const logIntercepted = () => { | |
const i = yesno.intercepted() | |
console.log( | |
'i.', | |
JSON.stringify( | |
i.map(x => ({ id: x.__id, status: x.response })), | |
null, | |
2 | |
) | |
) | |
yesno.clear() | |
} | |
await transactPutItem(item, tableName).catch(e => { | |
console.log(e) | |
logIntercepted() | |
throw e | |
}) | |
logIntercepted() | |
} | |
export const transactionTest2 = async () => { | |
const errors = [] | |
const iters = Array.from({ length: 200 }).map((x, i) => i) | |
for (const i of iters) { | |
await runTest(i).catch(e => errors.push(e)) | |
} | |
console.log('errors', errors.length) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment